ios – .onContinueUserAcitivty / .onOpenURL not known as when scanning QR-Code with NavigationStack

0
28
ios – .onContinueUserAcitivty / .onOpenURL not known as when scanning QR-Code with NavigationStack


I’ve an app for which I’ve registered a customized url scheme (I do know common urls are most popular lately however this was a enterprise choice).
Now, I need to open the app by scanning a QR-Code after which present the related view by studying the parameters from the url. This is a pattern hyperlink within the QR-Code:

my-schema://open-view/123

That is the code I am working with proper now:

@predominant
struct MyApp: App {
    @State personal var viewAction: ViewAction? = nil

    var physique: some Scene {
        WindowGroup {
            NavigationView {
                SomeView(motion: viewAction) // `viewAction` is being set in `handleOpenURL` and passes the retrieved information to subviews – works high quality
                ...
            }
            .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { userActivity in
                guard let url = userActivity.webpageURL else { return }
                handleOpenURL(url)
            }
            .onOpenURL(carry out: handleOpenURL)
        }
    }

As you possibly can see, I am utilizing each .onContinueUserActivity and .onOpenURL. That is as a result of typically, the previous known as for QR-Code scanning and the latter for any tapped urls, and typically each name .onOpenURL – idk why.

Now, for navigation, I am utilizing a NavigationView and all of it works high quality. Nevertheless, I am experiencing some hassle with NavigationView, and because it’s deprecated in favor for NavigationStack, I made a decision to modify to that.

When utilizing NavigationStack, the app nonetheless opens high quality from each a tapped hyperlink and a scanned QR-Code. Nevertheless, neither .onContinueUserActivity or .onOpenURL are being known as when scanning the QR-Code. Solely when tapping on the hyperlink from the QR-Code, the strategies are known as.

TL;DR

when utilizing NavigationStack, scanning a QR-Code to open the app does NOT name the strategies I should be known as so I can retrieve the url parameters and open the respective view.

I don’t know what this has to do with the navigation methodology, however that is what I discovered.

LEAVE A REPLY

Please enter your comment!
Please enter your name here