iOS Universal Links are not opening in-app

119,611

Solution 1

There are a few possible issues.

  1. Try pasting your domain into this link validator and make sure there are no issues: https://limitless-sierra-4673.herokuapp.com/ (credit to ShortStuffSushi -- see repo)

  2. iOS logs an error message in the system logs if you don't have TLS set up properly on the domain specified in your entitlements. It's buried in the OS logs, not application logs. The error message will look like Sep 21 14:27:01 Derricks-iPhone swcd[2044] <Notice>: 2015-09-21 02:27:01.878907 PM [SWC] ### Rejecting URL 'https://examplecustomdomain.com/apple-app-site-association' for auth method 'NSURLAuthenticationMethodServerTrust': -6754/0xFFFFE59E kAuthenticationErr. Error message pulled from here, quick (incomplete) instructions on using CloudFlare for TLS here.

  3. In my personal testing, clicking/typing in a link in Safari has never once opened the app directly. Clicking from other apps (iMessage, Mail, Slack, etc.) has worked. Others have reported that clicking links in Google search results have opened the app directly.

  4. Note that if a Universal Link succeeds in opening your app and then you click through to Safari (by tapping your site in the top right corner of the nav bar in app), then iOS stops opening the app when you visit that URL. Then in Safari, you can pull down to reveal a banner at the top of the page with "Open". I wasted a lot of time on this. Note that clicking through to the site => disabling UL seems path specific, based on the paths you specify in the apple-app-site-assocation file. So if you have separate routes, yoursite.com/a/* and yoursite.com/b/*, if you click yoursite.com/a/* and it opens your app directly, you then have the option in the top right corner of the app to click through to yoursite.com/a/*. If you do that, subsequent visits to yoursite.com/a/* will open in browser, not app. However, yoursite.com/b/* should be unaffected and still open your app directly.

Let me know if you discover what the issue is. I'm personally very curious about how Universal Links work and what edge cases exist. Good luck.

Solution 2

There are a lot of ways this can go wrong. Two points caused me trouble:

  • In Xcode, when you add the Associated Domains entitlement, each entry needs to start with applinks: and then your domain name. E.g. applinks:www.apple.com.

  • Though Xcode created an entitlements file for me, it did not include in my build: I had to click that box manually.

And yes, after doing that, it wasn't necessary to sign the apple-app-site-association file: it is just plain text, and it works, as long as it's served over HTTPS. (You'll still need to sign it if you're supporting iOS 8, though.)

Solution 3

To help debugging this issue, search for "swcd" in your device's console output when installing your app to see if registering your universal link worked or failed.

  1. Use an actual device, not the simulator.
  2. Delete the app from you device.
  3. Connect the device to your computer, and view the device's console output in xcode. (window -> devices -> [your device] -> open console). Keep this window open.
  4. Install your app and let it launch.
  5. Filter the console output to "swcd". If it's sucessful you will see something like the folowing screenshot. If it fails you'll see something else. If you don't see anything then you messed something fundamental like adding the Associated Domains entitlement.

Applink added successfully

Solution 4

There is apparently an error in the documentation for making the association file for Universal Links.

Where it says:

The value of the appID key is the app’s team ID and the bundle ID

it should say

The value of the appID key is the app’s Prefix and the bundle ID

For most apps, it seems that the Team ID and app prefixes are the same, but if your app has been in the store for many years, these values can be different.

To find this value, open the Member Center on https://developer.apple.com and look at "Certificates, Identifiers & Profiles", click "Identifiers", then "App IDs" in the table under "Identifiers". Find your app, and use the Prefix value and Bundle ID there to create your AppID for the association file.

Solution 5

To validate apple-app-site-association on the server side, you can use Apple's official validator.

https://search.developer.apple.com/appsearch-validation-tool/

Share:
119,611
Legolas
Author by

Legolas

I love the science behind learning.

Updated on July 15, 2021

Comments

  • Legolas
    Legolas almost 3 years

    So I followed this tutorial exactly and use the same values as the ones provided: https://blog.branch.io/how-to-setup-universal-links-to-deep-link-on-apple-ios-9

    The Apple Association file is also ready in the link directory:
    WEB_PAGE:PORT_NUMBER/apple-app-site-association

    Everything seems to be set up on this side.

    I've added the entitlements, updated the provisioning profile, and everything's set up.

    When I run the app on my device, and open the link http://WEB_PAGE:PORT_NUMBER, this always opens Safari.

    I even have breakpoints in the following method:

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

    But zilch.

    Has anyone perfected this? Is there something I'm missing?

  • Legolas
    Legolas over 8 years
    This is an awesome answer. I will need to dig into the error. Thanks for the link validation URL.
  • Kazzin
    Kazzin over 8 years
    I've gotten universal links working for iMessage and Mail, but when trying to open from Slack or Twitter, the links open is Safari. (Slack a SafariViewController and Twitter a web view). Twitter's universal links seem to be fine in Slack, iMessage, and Mail, while another app called Quip has them work in iMessage and Mail, but not Slack (same issue as us). Any ideas?
  • st.derrick
    st.derrick over 8 years
    I should go back and test extensively between apps/browsers using my test app. I'm not sure why Twitter would work in Slack but for your app it wouldn't. Related, one app I've advised claims that they have UL working and I can see that their apple-app-site-association file is correct, but I can't get links to open their app directly even in Mail and iMessage. Universal Links still seem finicky.
  • Kazzin
    Kazzin over 8 years
    Hmm very strange, they do seem quite finicky. Thanks for your input!
  • Legolas
    Legolas over 8 years
    Same thing. So weird. Sometimes it opens the app directly, sometime it opens the webView. I wish they made the documentation clear. Operation of this feature is erratic
  • LyricalPanda
    LyricalPanda over 8 years
    Does anyone know what the failed: -6756/0xFFFFE59C kTypeErr is for? The file doesn't have an extension and using rails to send_file 'path/apple-app-site-association', type: "application/pkcs7-mime". I can't find anything about this error
  • st.derrick
    st.derrick over 8 years
    I've seen this error when the apple-app-site-association file is not served over HTTPS
  • IPv6
    IPv6 over 8 years
    "Clicking from other apps (iMessage, Mail, Slack, etc.) has worked" - it also works when clicking from google search results inside safary (if it links to your page)
  • st.derrick
    st.derrick over 8 years
    Slack recently switched from using SFSafariViewController (which did not work with Universal Links) to opening Safari / respecting Universal Links. Seems like their experiment with SFSafariViewController was short lived
  • st.derrick
    st.derrick over 8 years
    @Martin I just moved the info to the original post -- good idea
  • Jeremy Hicks
    Jeremy Hicks over 8 years
    Regarding 1), it is no longer required that you sign your apple-app-site-association file if you are serving it over https.
  • Jeremy Hicks
    Jeremy Hicks over 8 years
    If I'm looking for the error in the syslogs, would I typically find that it /var/log/syslog on Debian/Ubuntu?
  • bhasker_kottapally
    bhasker_kottapally over 8 years
    @st.derrick "So if you have separate routes, yoursite.com/a/* and yoursite.com/b/*, if you click yoursite.com/a/* and it opens your app directly, you then have the option in the top right corner of the app to click through to yoursite.com/a/*. If you do that, subsequent visits to yoursite.com/a/* will open in browser, not app. However, yoursite.com/b/* should be unaffected and still open your app directly" are you sure about it. From what I tested, that does not seem to happen. Irrespective of the PATH, any URL from that domain seems to take to the web and not the app.
  • Nikhil Mathew
    Nikhil Mathew over 8 years
    @st.derrick - Regarding Your point 3 : "In my personal testing, clicking/typing in a link in Safari has never once opened the app directly.", Please check my answer. I had the same issue. But I figured out that UL doesn't work properly from the same domain. I checked with multiple iOS 9 devices. Some older devices were able to launch the app from the same domain. But some devices never launched the app on tapping the link, only "Open IN [Your app]" context menu item that shows up on long tapping the link would work in safari when the domain is same.
  • wrtsprt
    wrtsprt over 8 years
    That is curious. Apple states in the docs that for pure Universal Links and the use in iOS9 you don't need signing. Only if you want to support iOS 8 Handoff / Shared Web Credentials should you need to sign. Interesting! I have the same problem, so I am going to try signing.
  • Ankit Srivastava
    Ankit Srivastava over 8 years
    The above link fails to validate your ipa if you build and drag it to itunes and then crate an ipa out of it. You should archive your build properly and it would work.
  • Devy
    Devy over 8 years
    Signing is indeed optional. Tapping a link in Mobile Safari to trigger opening native iOS app is called "Web Browser–to–Native App Handoff", in which case, you will need to add activitycontinuation property to the apple-app-site-association json file. developer.apple.com/library/ios/documentation/UserExperience‌​/…
  • Phil Andrews
    Phil Andrews over 8 years
    I also had to delete the app completely from the test device and then build and run again before it finally worked.
  • cham
    cham over 8 years
    you save my day, this was my issue, though XCode created an entitlements file for me, it did not include in my build: I had to click that box manually.
  • mathz
    mathz over 8 years
    Restarting your iOS Device might help as well. I triple checked all settings and the configuration and I was absolutely sure that everything is correct but it still wouldn't work. Then I tried with another device and it worked perfectly. I then deleted the app from the original device, restarted the device and reinstalled the app, then it just worked...
  • Ivo
    Ivo about 8 years
    +1, This helped me a lot. Spend half a day figuring out why it didn't work and this seemed to be the case for me
  • iEngineer
    iEngineer about 8 years
    There is no option of app , only copy, open, add to reading list etc
  • iEngineer
    iEngineer about 8 years
    How to get back in app instead of safari if someone accidentally pressed website link on right corner of app ?
  • user361526
    user361526 almost 8 years
    Same problem here, I had to add the entitlements file to the build AND to delete the app on the device
  • Tony
    Tony almost 8 years
    Has anyone gotten universal links to work in a simulator? I've tried countless times and it never works. It does work using a real device with the same flows though.
  • Ben Flynn
    Ben Flynn almost 8 years
    I was doing SSL spoofing using Charles Proxy and this was resulting in a trust value of 4. When I turned off the proxy, it succeeded.
  • Albert Bori
    Albert Bori almost 8 years
    I haven't been able to test this either. Trying to get Safari to trigger universal links in the simulator has been futile, despite the fact that it works properly on a physical device.
  • Herbert Poul
    Herbert Poul almost 8 years
    Almost went crazy debugging this problem, but THIS was the solution or me. Maybe if it's not set up correctly and Mail app opens the link in safari it always opens in safari? no idea, but i once did the long press -> open in 'myapp' ... and now the links open correctly!
  • kishorer747
    kishorer747 almost 8 years
    I did not get Open in App banner anywhere. After long search, here is a solution: Type any link for your site in Notes app (which is a universal link). Now Click Done. Once it becomes a link, long click on it and select "Open in AppNAME-HERE" !
  • Gon
    Gon almost 8 years
    How to fix issue 4 in your answer by the programmer, not user? Could I disable the top right safari button when universal link open my app?
  • Josh Sklar
    Josh Sklar over 7 years
    This was not working for me when running on the iOS Simulator, but worked great when running on an actual device.
  • Josh Sklar
    Josh Sklar over 7 years
    Very helpful, thanks! Worked for me when running on an actual device, but not the iOS Simulator.
  • Charles A.
    Charles A. over 7 years
    Including the entitlements file in the build fixed the issue for me as well. It's worth noting that in Xcode 8 the target membership checkboxes in the File Inspector are actually disabled. I had to go to the build settings and add the entitlements file to the Copy Resources phase.
  • zai chang
    zai chang over 7 years
    This! The bundle version was totally what was causing my testing to fail, because I would go through all the above advice and my links would still launch Safari as iOS is using the cached result from the previous version of apple-app-site-association which had the wrong appId prefix
  • eonil
    eonil over 7 years
    The manual clearly says that "The file needs to be accessible via HTTPS—without any redirects".
  • andrew
    andrew over 7 years
    Thanks a lot for this solution. I was stuck up in this for almost a day. You saved my day.
  • Joris Weimar
    Joris Weimar over 7 years
    thanks for wasting that time and finding out what the issue was :) pulling down revealed the "open in the ... app" banner.
  • neiker
    neiker over 7 years
    Kyle, I think I love you! This answer save the day, thank you!
  • Roberto
    Roberto about 7 years
    The manual also clearly says that "For apps that run in iOS 9.3.1 and later, the uncompressed size of the apple-app-site-association file must be no greater than 128 KB, regardless of whether the file is signed." This file is 154 KB.
  • CoDe
    CoDe about 7 years
    @st.derrick Thanks for post. Beside, I still having same problem. Issue is it's almost overtime redirecting to Safari. I'm using Firebase service and creating common link for Android & iOS. For Android same link worked so perfect. Any suggestion on issue !!
  • nurider
    nurider about 7 years
    This was the secret sauce for me! Thank you thank you thank you!
  • jox
    jox almost 7 years
    3rd bullet, same here: wasted many hours figuring that out. Apple has even a nice very stupid explanation for it: "iOS respects the user’s most likely intent and opens the link in Safari" see yourself here.
  • Thang Pham
    Thang Pham almost 7 years
    @cham: can you guys elaborate on "though XCode created an entitlements file for me, it did not include in my build: I had to click that box manually."
  • Ti3t
    Ti3t over 6 years
    you saved my day, in deed my app was long time ago and app prefix is different from team ID.
  • Max Odnovolyk
    Max Odnovolyk over 6 years
    On iOS11 your server should explicitly return 404 status for: example.com/.well-known/apple-app-site-association then swcd uses fallback to root: example.com/apple-app-site-association. You can quickly check returned HTTP status with tools like Postman
  • anitteb
    anitteb over 6 years
    Could it be a problem, that my application communicates with website via http NOT https ?
  • maledr53
    maledr53 over 6 years
    That was it, have being dealing with this issue for hours, LAUNCHING THE APP FROM THE SAME DOMAIN MOSTLY FAILS. Thanks :)
  • BharathBob
    BharathBob about 6 years
    My app is opening when clicked on UL, but continueuseractivity delegate is never called, any one help me please?
  • Awais Fayyaz
    Awais Fayyaz about 6 years
    as @cham asked about "though XCode created an entitlements file for me, it did not include in my build: I had to click that box manually." which box had to be clicked. Where?
  • Hanane
    Hanane about 6 years
    the only thing that worked for me is 'open in safari', i wasted hours on this
  • kk-dev11
    kk-dev11 almost 6 years
    @st.derrick let's say your app has two views (A & B). Is it possible to open view A if you click on yoursite.com/a/* and open view B if you click on yoursite.com/b/*?
  • Ryan110
    Ryan110 almost 6 years
    i have problem with :// chars url remove special chars
  • s.zainulabideen
    s.zainulabideen over 5 years
    @AwaisFayyaz Go to Build Phases > Copy Bundle Resources. Click the plus sign then add your entitlement file.
  • Egist Li
    Egist Li over 5 years
    Thanks! My problem is the entitlements is not copied.
  • chib
    chib over 5 years
    This doesn't seem to work for me, I have tried everything to get them to work in the simulator to no avail. They work fine on the actual device, but that's not ideal for development/debug. I've tried long pressing the link and there is no "Open in app" option.
  • chib
    chib over 5 years
    I've not been able to get them to work in the simulator either. @AlbertBori did you get this working?
  • chib
    chib over 5 years
    I haven't got this to work, it always just opens up Safari. They do work when I run on an actual device though. Any ideas would be appreciated as it's a bit more painful debugging/developing without the simulator.
  • NYS
    NYS over 5 years
    I had the same problem and the device reboot solved it. Thanks!
  • Numan Tariq
    Numan Tariq over 5 years
    Excellent tip! I was adding https:// to the applinks: entitlement and also specifying the full path I wanted to listen to which were both mistakes. I was specifying example.com/path* where I should only be specifying my domain.com and the AASA file at example.com then specifies the path against my app's bundle id
  • dhin
    dhin about 5 years
    this is the only thing that works for me. thank you!
  • Jamshed Alam
    Jamshed Alam about 5 years
    Did anyone made it worked perfectly ? Question 1) We put the aasa file under .well-known directory. It accessible with domain/apple-app-site-association or domain.com/.well-known/apple-app-site-association . Which one is right ? Question 2) Does SSL certificate is must ? We are working on dev server now. From email app , i clicked the url i put on associated domain. It is not working. My aasa file : { "applinks": { "apps": [], "details": [ { "appID": "Prefix.appbundleID", "paths": ["*", "/"] } ] } }
  • rob5408
    rob5408 about 5 years
    I had a complete blindness for the fact that Xcode by default uses "webcredentials:" for associated domains and not "applinks:". This was the first answer that made me recheck what I had in my entitlements.
  • readyornot
    readyornot almost 5 years
    3 years later and we hit this exact issue. Adding activitycontinuation is what fixed it for us.
  • nalexn
    nalexn almost 5 years
    Can I wire you cash bonus?? I spent 2 days going through every step of this freaking universal link setup, nothing was helping until I tried your approach. I got really unfortunate to host my association file on a firebase's root folder for my domain, and it turned out that Apple queries .well-known/ subdirectory first, and firebase appear to respond to it with their own (!) correct association file that has no app linked. Goshhh how am I supposed to find this out, Apple?
  • Berkay Turancı
    Berkay Turancı almost 5 years
    Finally! Thanks a lot. Is it written in somewhere? Firebase should document in somewhere.
  • Fattie
    Fattie almost 5 years
    I'm almost certain they do not work in simulator. I'm familiar with all the other pitfalls, and I can never get them to work in simulator ..
  • FranticRock
    FranticRock almost 5 years
    applinks: prefix is what solved it for me. Adding my prefix, my Associated Domains Capabilities entry looks like this: applinks:mysubdomain.mydomain.com
  • Joshua Wolff
    Joshua Wolff over 4 years
    @iEngineer Force press on the link and click "Open in [#APPNAME]"
  • Joshua Wolff
    Joshua Wolff over 4 years
    @DFedor raises a good point, "It wasn't necessary to sign the apple-app-site-association file: it is just plain text, and it works, as long as it's served over HTTPS." The link used to 'validate' my file in #1 said, "Your file must be served with content type "application/pkcs7-mime." But, I was sure my file was served properly because aside from a domain name change, the settings and everything was the same as I had used successfully prior. Without any changes, I merely restarted my phone and the link opened up in app.
  • Joshua Wolff
    Joshua Wolff over 4 years
    Downvoter, please explain why you downvoted so that we can improve the answer if it is inaccurate.
  • vincenth
    vincenth over 4 years
    This was the solution for me. Great advice.
  • CyberMew
    CyberMew about 4 years
    Your links are 404'ed @st.derrick, possible to give an update?
  • Byteros
    Byteros about 4 years
    3rd bullet TOP !
  • Arno Teigseth
    Arno Teigseth about 4 years
    Ahhh great hint! I didn't know about this device console, just looking at the Xcode console output. My trouble was that 2 out of 3 deeplink domains DID work, but not that last one. And there in the console I saw that for my last domain I had misspelled it with "appllinks:<domain>" (2 L's) Oh man… anyway, thanks again for a great way of checking if Universal Links are actually registered! (I found the console logs also Removing of the links when uninstalling the app :+1 )
  • Nicholas Allio
    Nicholas Allio about 4 years
    is it supposed to be that verbose by default? Because I don't get such detailed log.. does this mean that the operation is not successful?
  • skornos
    skornos almost 4 years
    you'd need to add "exclude": true to components object in order to comment be true
  • luky
    luky over 3 years
    there is no swcd filtering i still see lot of not related rows
  • Rotem
    Rotem over 3 years
    3rd bullet should be the correct answer! I just spent 4 hours on this. Thank you
  • Anita
    Anita over 3 years
    @SurjeetRajput I have updated my answer, I copied the file from one of my production projects. This is working for me.
  • Jakub S.
    Jakub S. over 3 years
    "For Apps created after 2011 your App ID Prefix is your Team ID. However, for apps created during 2011 or before, it is possible to have different App ID Prefixes."
  • Pramod Tapaniya
    Pramod Tapaniya over 3 years
    Not working when i hit url from the browser and it work when i click url from messenger or whatsapp.
  • Pramod Tapaniya
    Pramod Tapaniya over 3 years
    Not working when i hit url from the browser and it work when i click url from messenger or whatsapp. Please help me
  • App Dev Guy
    App Dev Guy almost 3 years
    Links no longer valid. The image is the only thing helpful now.
  • Evgeny Karkan
    Evgeny Karkan almost 3 years
    How did you know what swcd is? Out of my curiosity.
  • mpoisot
    mpoisot almost 3 years
    @EvgenyKarkan honestly it's been so long I don't remember. I certainly didn't already know about swcd before I started trying to figure this out. I must have stumbled upon it, possibly on this exact SO question, and figured out a process to make it easy to filter since I needed to manually do it many times.
  • Huy Nguyen
    Huy Nguyen over 2 years
    really helpful to me. thansk!
  • Starwave
    Starwave over 2 years
    Wooooow, this is the diamond among the rubbles! Thank you!!
  • Dmitry Salnikov
    Dmitry Salnikov about 2 years
    I really can't believe in iOS 15 such bugs with universal links are still possible - but yes, thanks man you saved my day!
  • Huynh Inc
    Huynh Inc almost 2 years
    Can't understand what different between them?
  • luky
    luky almost 2 years
    maybe wrong quotes “