Can we test iOS Universal Links / Deep Links without apple-app-site-association (AASA)?
Asked Answered
L

3

8

I have implemented universal links into my app but for reason, AASA file is not going to be uploaded on server for now.

Locomobile answered 9/11, 2017 at 7:18 Comment(1)
Can you upload AASA to another server and test there? At least this will give you some confirmation that your App is configured correctly.Brachial
C
6

Yes you actually can!

You can test you app's response to a deep link without actually implementing the remote side by calling this function from terminal:

$ xcrun simctl openurl booted 'YOUR_LINK_HERE'

This will trigger the following callback in your app's appDelegate:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool

...which is exactly the behavior you should expect from a deep link.

just don't forget to actually have the simulator up ;-)

As for universal links - the appDelegate callback is slightly different, but its a very small mental leap:

func application(_ app: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        if let url = userActivity.webpageURL {
            // parse the url and decide how to handle the universal link

        }
    }
    return true
}
Crematorium answered 24/1, 2018 at 1:22 Comment(4)
How could you test Universal link URL without deploying AASA file into root server of your website? I think you need to deploy AASA file first.. can you give more details how it works?Softball
Is there any xcrun command if you're using an actual device that is connected and not the simulator?Pilarpilaster
I can't get the full URL in userActivity methods. My actual URL is example.com/6eZ4?class_id=4&member_id=18 but I'm only getting the short URL in userActivity example.com/6eZ4?class_id=4Kennel
This doesn't actually work, it does send the url to the simulator, and it passes it on to Safari. But without the association file, nothing actually happens with the App, it is not opened.Bouzoun
T
2

No, you must upload "apple-app-site-association" on the server with your bundle id and team id. You cant test without it. Also you cant test it using someone else's "apple-app-site-association" file as it's team id and bundle id will be different.

You can upload your AASA file on heroku server for testing purposes.

Tuning answered 9/11, 2017 at 10:29 Comment(2)
can you please suggest how can I test deep link by uploading AASA file on heroku server?Locomobile
i made free node server and kept my AASA file on the root. You can test you server by this validator "limitless-sierra-4673.herokuapp.com". Server should pass first five validators. I hava attached the url below for sample. spooky-spell-19694.herokuapp.com/apple-app-site-association Add base url (spooky-spell-19694.herokuapp.com) in the associated domians in xcode. Test all the url by handling them through app delegate.Tuning
F
2

Apple does not appear to support this.

However, you can simply call the delegate method directly from anywhere in your program.

NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb];
activity.webpageURL = [NSURL URLWithString:@"https://<your-domain.com>/route"];

[UIApplication.sharedApplication.delegate application: UIApplication.sharedApplication continueUserActivity:activity restorationHandler:^(id restorableObjects) {

}];
Fruitful answered 14/11, 2018 at 22:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.