Hugo
Hugo

Reputation: 994

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:).

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.

Upvotes: 4

Views: 1861

Answers (2)

budiDino
budiDino

Reputation: 13527

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)")
  }
}

Upvotes: 6

Liaz Kamper
Liaz Kamper

Reputation: 126

Thanks for your using AppsFlyer's public demo of App Clip and for highlighting this issue. I really appreciate it.

I can confirm you were doing great, this functionality was broken sometime after Beta 5.

Please follow and comment on this issue here

Upvotes: 1

Related Questions