Rahul
Rahul

Reputation: 905

Deep linking is not working in SwiftUI iOS (open url appdelegate method is not triggerd)?

I am working on SwiftUI app in which trying to perform deep linking. when I manually open the browser and put "myapp://" its navigating to app correctly. But in actual I am opening safari within app and after deep link success I want to call below appdelegate method

I am using sfsafariviewcontroller

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
            print("myapp")
        return true
    }

below is my work

enter image description here

Thank You for help

Upvotes: 2

Views: 1291

Answers (1)

Ks 2000
Ks 2000

Reputation: 11

@main
struct SomeApp: App {
    var body: some Scene{
        WindowGroup{
            Content()
                .onOpenURL{url in
                    //handle any action from deep link
                }
        }
    }
}

struct Content: View {
    var body: some View {
        Text("Hello World")
    }
}

After set deeplink in info.plist you can handle deeplink via method onOpenURL

Upvotes: 1

Related Questions