iosswiftuiscenedelegateapple-appclips

iOS App Clip - Scanned QR opens the app, but doesn't provide the URL


I'm struggling with App Clips and what appears to be a Black Box technology.

So, I have it set up where it "works". I can scan a QR code, and it knows the embedded URL is an invocation URL for my app.

If the app is being launched from a "cold start", it works just fine.

If the app (or app clip) is already running in the background, the app will be foregrounded, and the following SceneDelegate method is called:

    func scene(
        _ scene: UIScene,
        willContinueUserActivityWithType userActivityType: String
    ) {

        log.info_("Continue User Activity with type: \(userActivityType)")
        if let activity = scene.userActivity {
            log.info_("\(activity)")
        } else {
            log.info("No activity provided!") // PROBLEM!
        }
    }

So one would expect that the userActivity is somehow defined, especially the .webpageURL

Otherwise, how do I get the information from the scanned QRCode so I can handle it properly?

This whole App Clip stuff just seems busted / unnecessarily cryptic on the Apple side. Help appreciated!


Solution

  • It turns out the Apple documentation is wrong.

    It will tell you (source):

    If you use a scene-based lifecycle, implement the scene(:willConnectTo:options:) and scene(:willContinueUserActivityWithType:) callbacks.

    Which leads to problems, as the activity is often nil, which you would have to grab via scene.userActivity

    You should actually implement the optional UISceneDelegate method:

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

    and then the invocationURL is available via userActivity.webpageURL

    (Note: I do still have an empty willContinue method implementation. Didn't verify if it's necessary to keep.)