Search code examples
ios14apple-appclips

SceneDelegate's "continue" not called when launching App Clip from Xcode


I am trying to test my app clip's url handler by running the app clip from Xcode. However the URL method handler (SceneDelegate's continue method) never gets called, contrary to Apple's documentation documentation, which states:

For a UIKit-based app clip and full app that support scene-based app life-cycle events, implement the callbacks defined in UISceneDelegate. For example, implement scene(_:continue:) callback to access the user activity object.

For a UIKit-based app clip and full app that respond to app-based life-cycle events, implement the callbacks defined in UIApplicationDelegate. Be sure to implement the application(:continue:restorationHandler:) callback, because you don’t have access to the NSUserActivity object in application(:didFinishLaunchingWithOptions:).

  • The app delegate does not implement the application(_:continue:restorationHandler:) method
  • The app clip's scheme has the _XCApplClipURL parameter enabled and set to https://fruits.com/check?fruit_name=bananas
  • The app clip's Associated Domain lists appclips:fruits.com
  • The app clip's SceneDelegate is as follows
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?
    
    
    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {     
        // UGHH!!! Never gets called
        print("AppClip invocation url is : \(incomingURL)")
        
    }
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // OK!! This gets called
        guard let _ = (scene as? UIWindowScene) else { return } 
    }
}

I have been banging my head on the walls for the last 2 days. What am I missing?

Note: I am using this sample app available in github, just modified the signing configuration to get the app clip to compile & run.


Solution

  • The continue method mentioned is only called when your app is invoked after it was previously opened. In order to get the value set in _XCApplClipURL the first time your app is launched, you need to use the second method you mentioned (scene willConnectTo session).

    You can try something like this:

    if let activity = connectionOptions.userActivities.filter({ $0.activityType == NSUserActivityTypeBrowsingWeb }).first {
      if let url = activity.webpageURL {
        print("incoming URL: \(url)")
      }
    }