0

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

Rahul
  • 537
  • 1
  • 7
  • 19
  • Does this answer your question? [Using UIApplicationDelegateAdaptor to get callbacks from userDidAcceptCloudKitShareWith not working](https://stackoverflow.com/questions/67541441/using-uiapplicationdelegateadaptor-to-get-callbacks-from-userdidacceptcloudkitsh) – lorem ipsum Jul 21 '21 at 17:51
  • https://mokacoding.com/blog/how-to-migrate-from-swiftui-to-uikit-life-cycle/ – Threadripper Jul 22 '21 at 05:29

1 Answers1

1

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()
        }
    }
}
ScottM
  • 7,108
  • 1
  • 25
  • 42