swift - IOS - DeepLink - cannot get url parameters - Stack Overflow

admin2025-04-17  3

I try to open my app with deeplink. When I type: pl.myapp.test://test?param1=1 in Safari my app opens but I cannot get any data from that link

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>pl.myapp.test</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>pl.myapp.test</string>
        </array>
    </dict>
</array>

I have also:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { 
  NSLog("URL: %@", url.absoluteString)
  print("URL: \(url)")
  logToFile("URL: \(url.absoluteString)")
}

and

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    logToFile("test")
    
    if let url = launchOptions?[.url] as? URL {
      NSLog("URL: %@", url.absoluteString)
      print("URL: \(url)")
      logToFile("URL: \(url.absoluteString)")
    }
}

So link works but it looks like none of that func is called

Edit: I can see that this works but why AppDelegate doesn?

@main
struct iOSApp: App {
   @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    var body: some Scene {
        WindowGroup {
            MyView() 
                .onOpenURL { url in
                NSLog("App opened deeplink: \(url.absoluteString)")
            }
        }
    }
}
转载请注明原文地址:http://anycun.com/QandA/1744876717a88880.html