onOpenURL(perform:) vs application(_:open:options:)

Hi, community:

I was trying to move from application(_:open:options:) (UIKit) to onOpenURL(perform:) (SwiftUI). Maybe there's something that I'm missing.

In UIKit you can say to the system that you won't handle the URL then the app is not opened, but when I use onOpenURL(perform:) it is always opened. Is there any way to achieve the same behavior?

Thanks in advance.

Hi @JesusMG , it sounds like you're looking for openURLAction

https://developer.apple.com/documentation/swiftui/openurlaction

Thanks for your reply @sha921, but it is not what I'm looking for. The openURLAction is for open urls programmatically vs what I'm looking that it's someone runs a scheme or a Dee-link and you can manage it.

hm, how are you handling the incoming links in onOpenURL? I'd expect it to look like the following to handle what is getting opened instead of just opening everything no matter what.

.onOpenURL { url in
      guard url.scheme == "someString" else { return } 
      guard let components = URLComponents(...) else { return }
}

@sha921

onOpenURL(perform:) vs application(_:open:options:)
 
 
Q