ok after weeks of getting nowhere on this, I found the cause.
For me this was caused by having multiple .onOpenURL's similar to you. I had one in each view that I wanted to action the url. While it worked most times, this was causing unpredictable results intermittently for my app and gave this error each time.
So I moved the .onOpenURL to the App file then used an environment variable to pass the url to the views I wanted to action it.
something like this:
struct MyApp: App {
@State var deepLink: URL? = nil
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.deepLink, self.deepLink)
.onOpenURL { url in
guard url.scheme == "myApp" else { return }
self.deepLink = url
/* clear the environment variable so you can send the same url twice */
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(200), execute: {
self.deepLink = nil
})
}
}
}
}
remember to setup your environment variables
import SwiftUI
struct deepLinkKey: EnvironmentKey {
static var defaultValue: URL? = nil
}
extension EnvironmentValues {
var deepLink: URL? {
get { self[deepLinkKey.self] }
set { self[deepLinkKey.self] = newValue }
}
}
then in the views u want to use it in
var body: some View {
content()
.onChange(of:deepLink, perform: { url in
guard url?.scheme == "myApp" else { return }
/* parse the url here*/
})
}
btw thanks for mentioning onOpenURL, otherwise I would never have found it.