question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get deeplink URL in iOS?

See original GitHub issue

From @zahid-dapperapps on February 13, 2017 13:39

Documentation has code for android that is working and I am able to get value of what is being passed.

application.android.on(application.AndroidApplication.activityResumedEvent, (args) => {
    var intentData = args.activity.getIntent().getData();
});

How can I do the same for iOS? documentation has code for iOS for resume event but it doesn’t really show how to get whats being passed via deeplink url

application.on(application.resumeEvent, function (args: application.ApplicationEventData) {
    if (args.android) {
        console.log("Activity:================= " + args.android);
    } else if (args.ios) {
        console.log("UIApplication:============== " + args.ios);
    }
});

Copied from original issue: NativeScript/ios-runtime#727

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
hypery2kcommented, Mar 27, 2017

you could take a look at my plugin: https://www.npmjs.com/package/nativescript-urlhandler

4reactions
tsonevncommented, Feb 14, 2017

Hi @zahid-dapperapps, To be able to use a deep link in iOS, you should make some changes in your project Info.plist and implement applicationHandleOpenURL delegate method, which allows you to get the URL. You could review the below-attached description, how you could do that in your app.

The first step is to include CFBundleURLName key in your app/App_Resources/iOS/Info.plist file. For example:

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string><your app id></string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>appgo</string>
                <string>yourSecondScheme</string>
            </array>
        </dict>
    </array>

<your app id> could get it from the project package.json file and should look like the following string org.nativescript.issue3632.

To be able to implement UIApplicationDelegate and its applicationHandleOpenURL method, you should install tns-platform-declarations with npm install tns-platform-declarations --save and to follow setup instructions in npm here.

The final steps is to implement the needed method in app.ts file for TypeScript project and app.js file for pure JavaScript template:

import "./bundle-config";
import * as app from 'application';
var application = require("application");





application.on(app.resumeEvent, function (args) {
    if (args.android) {
        console.log("Activity: " + args.android);
    }
});


function getParams(url){
    console.log(url);
    var resulturl:string = (<any>NSString)(url).toString();;
    if(resulturl.substring(0,5)=="appgo"){
       console.log(getParameterByName("test", resulturl));
    }

}

function getParameterByName(name, url) {
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return results[2].replace(/\+/g, " ");
}

class newIOSApplication extends NSObject implements UIApplicationDelegate{
static ObjCProtocols = [UIApplicationDelegate];
        applicationHandleOpenURL(app, url): boolean {
            getParams(url);
            return true;
        }
}
application.ios.delegate = newIOSApplication;

app.start({ moduleName: 'main-page' });

to be able to open the app with some parameters you could use URL similar to appgo://org.nativescript.issue3632?test=test and getParameterByName allows you to get single parameter.

Hope this information helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deep linking using URL scheme in iOS - Halodoc Blog
We'll look at deep linking on iOS and how to make an app's URL scheme. ... At the bottom of the page, you'll...
Read more >
Deep linking and URL scheme in iOS
When we talk about deep linking for mobile app, it means creating a specific URL to open a mobile application. It separate into...
Read more >
What is Deep Linking in iOS? - Originate
Deep linking consists of using a hyperlink that links to a specific piece of content within an app. The specific content could be...
Read more >
Handling deeplinks in your app - Donny Wals
On iOS, it's possible to send users from one app to the next or to send them from a webpage into an app....
Read more >
Deep Linking in iOS Using URL Scheme - Dev Genius
Deep linking is the use of semantic links to guide a user to particular content in-app. How to implement Deep linking in iOS?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found