Universal links not working in development

2019-04-23 14:34发布

问题:

I am trying to create Universal links for my app. I am using the apple validation tool to test my server configuration (https://search.developer.apple.com/appsearch-validation-tool/) and everything looks fine.

So I run my app which has the:

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler

method implemented but my app never opens. I can only see Safari. Entitlements are also added to XCode. The funny thing is that on the smart app banner I never get the word open but I get the view button so that I can download it form the app store. Am I doing something wrong or must my app be uploaded to the appstore so that the links can be opened by it?

回答1:

For me the problem was that in the Appstore version I clicked once on the top right to get forwarded to the Safari page. This behaviour was saved even through uninstall and new installations of the app. In the dev version I never clicked on the top right corner and therefore universal linking worked all the time.

How to fix it: For example go to notes and create a link https://example.com/whatever now long press on this link and select Open in "<App Name>"



回答2:

  • let's start with: your app does NOT have to be uploaded to the app store for this to work.

  • is your development hitting the exact same web server? no dev / qual.mydomain.com?

  • verify that the Team ID / bundle identifier combination are correct in your JSON file

  • send the link to yourself via messages app or mail and you long press it. do you get the "open in 'YOUR APPLICATION'"? That would mean it is basically working, you 'just' have a problem with Safari (There are reports of the Universal Links not opening from the same domain in Safari). also apparently iOS can be in a kind of 'mode' to not open the app anymore until you explicitly ask Safari to do that again (see this answer)

  • do you see any lines in the device log from swcd, those could give details about any errors with the JSON file download

  • after running the app from Xcode for the first time on a clean device, you should also see the hit on your web server downloading the apple-app-site-association file

UPDATE:

  • if you're using the root of your registered domain as the universal link make sure to checkout this answer on stack overflow. Apparently for this to work, they had to include both paths: "*" as well as "/".