1

I am working on custom URL scheme basically i am new with us functionality.

What i done before?

I implemented this successfully,i create simple url "myApp" now when i hit this url on safari like (myApp://) its launch my application.

My code

i used:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

What i want?

  • Basically i want to implement two things that is:
  • when an user hit a link on safari if an application is installed on device,through that link application should launch.That point i already done successfully.
  • The second point which i can't done yet,after trying a lot but i couldn't found any solution yet,that is:
  • If an application is not installed on device that link should redirect to app store where user can installed application.

If it is possible,then please tell me how to do that,please refer me any link,example or your answer also help me.Thanks in advance

13
  • you can't handle through custom url scheme when your application will uploaded to the appstore then use that link for this . it will handle both situation for you. Commented Jul 21, 2017 at 5:04
  • ok thanks buddy,but please explain me a lit bit more. i have also an application that is uploaded to appstore now what i do for that link.....??basically i can't get your point Commented Jul 21, 2017 at 5:13
  • call this url in your safari and check : itunes.apple.com/in/app/visiting-card-diary/id995151182?mt=8 . you will understand flow Commented Jul 21, 2017 at 5:16
  • You can't handle this flow manually . os will manage for you so if any query let me know . Commented Jul 21, 2017 at 5:25
  • it means as you said that,not required to do any thing...??shall i remove open url code..??or os manage it automatically ..?? Commented Jul 21, 2017 at 5:30

2 Answers 2

2

What you are describing is called Deep Linking. It's a very common app feature to implement — most apps have it — and conceptually, it seems like an easy thing to build. However, it's complicated to get right, and there are a lot of edge cases.

You basically need to accomplish two things:

  1. If the app is installed: open the app and route users to the correct content inside it.
  2. If the app is NOT installed: forward users to the App Store so they can download it. Ideally, also route users to the correct content inside the app after downloading (this is known as 'deferred deep linking').

While not required, you'll also probably want to track all of this activity so you can see what is working.

If the app is installed

Your existing custom URI scheme fits into this category. However, Apple has decided that custom URI schemes are not a good technology, and deprecated them with iOS 9 in favor of Universal Links.

Apple is right about this. Custom URI schemes have a number of problems, but these are the biggest:

  • There is no fallback if the app isn't installed. In fact, you get an error.
  • They often aren't recognized as links the user can click.

To work around these, it used to be possible to use a regular http:// link, and then insert a redirect on the destination page to forward the user to your custom URI scheme, thereby opening the app. If that redirect failed, you could then redirect users to the App Store instead, seamlessly. This is the part Apple broke in iOS 9 to drive adoption of Universal Links.

Universal Links are a better user experience, because they are http:// links by default and avoid nasty errors. However, they are hard to set up and still don't work everywhere.

To ensure your users end up inside the app when they have it installed, you need to support both Universal Links and a custom URI scheme, and even then there are a lot of edge cases like Facebook and Twitter which require special handling.

If the app is NOT installed

In this case, the user will end up on your http:// fallback URL. At this point, you have two options:

  1. Immediately forward the user directly to the App Store.
  2. Send the user to your mobile website (and then use something like a smart banner to give them the option of going to the App Store).

Most large brands prefer the second option. Smaller apps often go with the first approach, especially if they don't have a website.

To forward the user to the App Store, you can use a Javascript redirect like this:

<script type="text/javascript">
  window.onload = function() {
    window.location = "https://itunes.apple.com/app/id1121012049";
  };
</script>

Until recently, it was possible to use a HTTP redirect for better speed, but Apple changed some behavior in Safari with iOS 10.3, so this no longer works as well.

Deferred deep linking

Unfortunately there's no native way to accomplish this last piece on either iOS or Android. To make this work, you need a remote server to close the loop. You can build this yourself, but you really shouldn't for a lot of reasons, not the least of which being you have more important things to do.

Bottom line

Deep linking is very complicated. Most apps today don't attempt to set it up by building an in-house system. Free hosted deep link services like Branch.io (full disclosure: they're so awesome I work with them) and Firebase Dynamic Links can handle all of this for you, and ensure you are always up to date with the latest standards and edge cases.

See here for a video overview I made of everything you need to know about this.

Sign up to request clarification or add additional context in comments.

6 Comments

Dear,could you please tell me one thing...?? if i simply type on safari myApp:// its open my application. Now in my mail i have h simple link.. www.myApp.com/user/profile when i click on this link its not opining my app ...?? could you please plz tell why its not opning my app...??what should i do..?? Thanks for helping me...
That's actually covered in my answer 😊. Give it another read!
Dear Alex Bauer,sorry i can't get a point after read it again... actually the second point if app is not install redirect to app store is done... its working fine. but the thing where i stuck that is.... i simply add a url scheme "myApp", when i type "myApp://" on safari it will open my app but when i click on link "www.myApp.com" here actually i am facing the problem.. can't open my app.. what the changes required...? please help me a lit bit more... Thanks
You are fundamentally misunderstanding concept of a custom URI scheme Registering for myApp:// has nothing at all to do with whether your app will respond to https://www.myApp.com links; these are completely different. The myApp:// part is equivalent to https://.
so what can i do...?? i can't understand how can i open my application through link,that link is in my mail and the he link is... www.myApp.com,please refer me an example through which i got the point. Thanks for help Alex
|
0

In AppDelegate.m call this:

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;{
    NSLog(@"url recieved: %@", url);
    NSLog(@"query string: %@", [url query]);
    NSLog(@"host: %@", [url host]);
    NSLog(@"url path: %@", [url path]);
    NSDictionary *dict = [self parseQueryString:[url query]];
    NSLog(@"query dict: %@", dict);
    if ([[url host] isEqualToString:@"login"]) {
        [self setupHomeScreen:NO type:@"" entityId:@""];
        [self _endSession];
        return YES;
    } else if ([[url host] isEqualToString:@"smartoffice"]) {

        NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
        NSRange needle = [url.absoluteString rangeOfString:@"?" options:NSCaseInsensitiveSearch];
        NSString *data = nil;

        if(needle.location != NSNotFound) {
            NSUInteger start = needle.location + 1;
            NSUInteger end = [url.absoluteString length] - start;
            data = [url.absoluteString substringWithRange:NSMakeRange(start, end)];
        }

        for (NSString *param in [data componentsSeparatedByString:@"&"]) {
            NSArray *keyvalue = [param componentsSeparatedByString:@"="];
            if([keyvalue count] == 2){
                [result setObject:[keyvalue objectAtIndex:1] forKey:[keyvalue objectAtIndex:0]];
            }
        }
        NSString *entityID = ([result objectForKey:@"secondparameter"]);
        NSString *type = [result objectForKey:@"parameter"];
        [self setupHomeScreen:YES type:type entityId:entityID];
        //[self setupHomeScreen:YES type:@"TASK" entityId:@"160315"];
        return result;
    } else {
        NSLog(@"myApp is not installed");
        [self setupHomeScreen:NO type:@"0" entityId:@"0"];
    }
    return NO;
}

URL Type in Xcode Info

Open Xcode, got to Project Settings -> Info, and add inside ‘The URL Types” section a new URL scheme.

That is the scheme ://resource. So we go ahead and type com.myApp://

Fo me its backofficeapp://

Now use this link on Safari

backofficeapp://smartoffice/1?parameter=TASK&secondparameter=157536

Where

parameter = “TASK”

secondparameter = “taskID” // #iOS Mobile 2020 = 157536

This parameter is for landing on a specific screen.

Remember this URL won’t work if the app is not installed.

1 Comment

backofficeapp:// This one only redirects you to a landing page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.