7

I've been trying for a while now to get universal links of iOS10 to work but it's not working till now.

I have an apple-app-site-association configured. Have tried using the root domain, using a subfolder, on the same server or another. In all cases I am redirected to safari web page with a drop down to open my app as an option enter image description here What am I missing?

Hazem Hagrass
  • 9,329
  • 10
  • 32
  • 54
  • 2
    You have to press the OPEN button in safari once. Subsequent calls should open your app instead of the safari. – Bilal May 08 '17 at 08:36
  • 1
    Thanks for your reply, but I'm sure that there is a way to be done rather thank that – Hazem Hagrass May 08 '17 at 08:38
  • 1
    Just a note ... You should delete and reinstall the app if you change apple-app-site-association ...... iOS caches app associations and refreshes after some time but on a fresh install it always does... – Bilal May 08 '17 at 08:57
  • 1
    First: test your webpage https://search.developer.apple.com/appsearch-validation-tool/ – Ahmed Lotfy May 08 '17 at 16:28

3 Answers3

17

After spending some time trying to configure Universal Links here is what I have learned so far:

1 - Universal Links DO NOT work with redirects or when you type your link in Safari address bar and hit enter.

2 - Type your address in Notes and click on it, if your app opens directly it means you have everything set-up correctly.

3 - Universal Links work when user performs an action on your website, to try this add a button to your website/blog and link it to the Universal Link implemented to open your app. Now open your website/blog in Safari, and click the button, it will directly open your app.

4 - When you click on 'Open' in Safari, subsequent calls won't open the app directly, for reasons mentioned in point 1.

Hope this helps :)

Tejas K
  • 682
  • 11
  • 28
  • 3
    Update - it works with redirects (tested on iOS 11 & iOS 12) – Vagif Sep 12 '18 at 17:44
  • suppose I have a notes app, and I have a link over there, upon tapping which it should redirect to same notes app but it is opening the link in safari only. – krishan kumar Nov 09 '20 at 18:57
  • @krishankumar did you find the solution to your problem? – Manoj Jan 12 '21 at 12:48
  • 1
    @Manoj, I was unable to find any native way but what we have done is, we process URLs before calling 'openUrl' method, process means we check the validity of the url and if that is a valid one then we handle by ourself. – krishan kumar Jan 13 '21 at 08:59
11

You have probably tapped a small button on the device status bar while using the app, that led you back to the web site. Once you do that, the system would remember that and would always launch Safari when a universal link to your app is tapped. To undo that, long-tap the link, and in the menu that pops up, choose "Open with [your app]"

Arik Segal
  • 2,963
  • 2
  • 17
  • 29
  • This is the correct answer. The fact that there is an Open banner at the top of the webpage proves everything else is configured correctly. – Alex Bauer May 08 '17 at 17:32
-1

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:// // This one only redirects you to a landing page.

OR

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.

Chandan Anand
  • 179
  • 1
  • 11