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:).
application(_:continue:restorationHandler:) methodhttps://fruits.com/check?fruit_name=bananasAssociated Domain lists appclips:fruits.comSceneDelegate is as followsclass 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.
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)")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With