Reputation: 895
I am converting my UIKit app to SwiftUI app, in my UIKit project I am passing some url to webview and getting some result (dynamic url) then below appdelegate method gets call
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
but same thing I want to implement in SwiftUI and not sure what approach is there for this kind of thing in SwiftUI.
It will be great help if I get some pointer or code for same.
Thank You for help
Upvotes: 0
Views: 1212
Reputation: 10404
You can create a custom class that conforms to UIApplicationDelegate
, and then use the @UIApplicationDelegateAdaptor
to tell your SwiftUI app about it:
class MyAppDelegate: NSObject, UIApplicationDelegate {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
// your code here
}
}
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(MyAppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Upvotes: 1