Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Universal Link opens app, does not trigger app delegate methods

I am trying to enable universal links on iOS, (as part of Firebase's password-less sign-up). Testing locally on iOS 13.2.

The apple-app-site-associated (AASA) JSON looks as such (https://lokitools.page.link/apple-app-site-association):

{"applinks":{"apps":[],"details":[{"appID":"43S54AHEMG.com.jkalash.Loki","paths":["NOT /_/*","/*"]}]}}

Universal links do open the app, however I am unable to handle the app opening from them. Delegate methods:

  1. application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
  2. application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool

do not get called, when opening from universal links. Tried both apps running in the background and force closed. AASA validator (https://branch.io/resources/aasa-validator/) says file looks good, and I have tried troubleshooting by re-installing app and observing console logs for swcd (https://ios13.dev/universal-links-debugging-on-ios-13-cjwsux93w001p6ws1swtstmzc) but nothing out of the ordinary shows up and it does look like the AASA file was downloaded.

I have also tried following Apple's troubleshooting guide (https://developer.apple.com/library/archive/qa/qa1916/_index.html) but the final step which fails (step 8) does not cover my case which is the app does open (iOS detects universal links), but the delegate methods just don't get called.

like image 706
Joe Avatar asked Jan 01 '20 12:01

Joe


3 Answers

Turns out this is not a universal links specific problem, but a change in iOS 13's way of triggering app lifecycle events. Instead of coming through UIApplicationDelegate, they come through UISceneDelegate.

One confusing thing is that the app delegate methods aren't deprecated so you won't get a warning if you have both app delegate and scene delegate methods in place but only one will be called.

Refer to App delegate methods aren't being called in iOS 13 for a comprehensive answer

like image 191
Joe Avatar answered Nov 11 '22 06:11

Joe


I am using iOS 13 with Swift 5, replace the application (: continue: restorationHandler :) method of the AppDelegate.swift file and add the scene (: continue :) method to the SceneDelgate.swift file

In my case in the SceneDelegate.swift file add the following:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {

    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
        let urlToOpen = userActivity.webpageURL else {
            return
    }

    handleURL(urlToOpen)
}
like image 28
Juan Manuel Garcia Carmona Avatar answered Nov 11 '22 04:11

Juan Manuel Garcia Carmona


If you use Google Analytics, please refer to my here. The issue may be caused by method swizzling.

like image 20
whitney13625 Avatar answered Nov 11 '22 06:11

whitney13625