iOS Question [SOLVED] Universal Links in iOS --> how to?

JordiCP

Expert
Licensed User
Longtime User
I have an app that needs to support Universal Links. I have tried with URLScheme, and it works, but it is not exactly what I need.

Searching the forum, I've found a couple of old threads requesting it, where the answer seems to be that it is possible with a customized main
, but they are quite old and I wonder if support for universal links has later been added and I have missed further posts.

What I have tried up to now (according to Apple documentation and other links):
B4I App
  • Add 'Associated domains' capability to my app-Id and generate new provisioning profiles (adhoc and store)
  • Add #Entitlement:<key>com.apple.developer.associated-domains</key><array><string>applinks:www.mydomain.com</string></array>
  • (Also tried the above with #PlistExtra, just in case)
Customer's webSite:
  • A file ( /.well-known/apple-app-site-association ) has been added, with the needed info to allow universal links for my app

It doesn't work for me (the browser just goes to the link). For more clues, in my iPhone's Settings >Developer, there is a diagnosis utility which tells me that the intended link is not associated to any installed app.

My question is: are universal Links supported with B4I, even if it is with some sort of workaround, and if so, how could I do it?
 

Sandman

Expert
Licensed User
Longtime User
a diagnosis utility which tells me that the intended link is not associated to any installed app
I don't have any relevant information to share, sorry. Just a couple of questions that strike me as possible issues, typically things one can mess up when juggling 1000 different things and the mind glitches ever so slightly. :)

1. Are you sure that the installed version is your latest version, with the #Entitlement (or #PlistExtra)?

2. Are you absolutely certain that the #entitlement key is correct, and that the value is correctly specified?
ull contents of the apple-app-site-association (again same search-replace).


In addition, I imagine it would be great if you shared exactly what you specified as associated domains for your app-id. (Just do a simple search-replace so it says example.com if you want to keep it anonymous.) And then also your exact #Entitlement keys (same search-replace) and finally the f


My question is: are universal Links supported with B4I, even if it is with some sort of workaround, and if so, how could I do it?
Considering that iOS doesn't even acknowledge your universal links I would say the issue is before B4i even comes into the picture.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
The attached zip file includes a modified main.m file which implements the continueUserActivity method. Put it inside Files\Special.
Thanks Erel :) Just added this piece. Still doesn't work but I guess it is because of server issues (*)

Considering that iOS doesn't even acknowledge your universal links I would say the issue is before B4i even comes into the picture.
Good catch, thanks. I had an extra character in the #Entitlement. Now iOS diagnosis utility recognizes the universal link. I have found out that for this iOS tool, only what the app declares is taken into account (doesn't even look at the webserver's AASA file)


(*) There is another problem that the server's AASA file is not valid because of a server certificate issue (AASA validity can be checked using this or other tools: https://apnspush.com/aasa-validator/) -> also, seems that it is not enough to place the AASA file where it corresponds, since Safari navigator won't directly search for it in order to validate the universal link, but instead consult Apple's CDN -> this means that this apple service must be able to search/find the AASA file, meaning that the AASA CDN bot must not be blocked, among others.

(Follow-up, in case anyone might be after the same issue)
While the server certificate issue is solved, I found this: https://nishbhasin.medium.com/apple-universal-link-setup-in-ios-131a508b45d1
There seems to be a way to check if universal links are well implemented in the app during development, apparently directly accessing the AASA file (which allows for on-the-fly changes during development, avoiding CDN propagation delay issues). It requires:
  • Enabling develpment mode in the iPhone
  • Using a development certificate/profile
  • Add "?mode=developer" to the #Entitlement's domain
Unfortunately, it still doesn't work for me, perhaps because of the same certificate issues, so I'll have to wait until the customer fixes it :oops: and see if more steps are needed.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
(follow-up)

Switched to a domain with a valid certificate. No joy yet.

  • On the domain, everything seems to be ok. It is recognized (using https://apnspush.com/aasa-validator/), and AASA file content is the same as Apple's CDN, so there are no propagation delay issues
  • On the app, declaration of universal links pointing to that domain also seems to be ok according to the diagnosis in developer mode, and customized main.m has been added to Files/Special.

If someone has succeeded implementing universal links with iOS, please let me know :)
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Finally solved :) Thanks @Erel for the missing piece and @Sandman for the support testing it.

Just for convenience, I 'moved' @Erel's code on main.c file to the end of B4I's main, so that everything can be seen in the editor. I believe it is ok and hope I haven't broken anything :)
B4X:
#if OBJC

@end
@implementation B4IAppDelegate (universallink)
- (BOOL)application:(UIApplication *)application
        continueUserActivity:(NSUserActivity *)userActivity
            restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
    NSLog(@"continueUserActivity method");
    if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
        NSURL *url = userActivity.webpageURL;
        NSLog(@"Received Universal Link: %@", url.absoluteString);
        // Custom user code here if needed.
        return YES;
    }
    return NO;
} 

#End If
 
Upvote 0
Top