Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Links Firebase function not being called at all Xcode 12?

So I have a dynamic link that is working in that it opens up the app when I click on it but the handling of the dynamic link doesn't happen. This is because application function seen below is never entered and I'm not sure why...

func handleIncomingDynamicLink(_ dynamicLink: DynamicLink){
    guard let url = dynamicLink.url else {
        print("That's weird. My dynamic link object has no url")
        return
    }
    print("Your incoming link parameter is \(url.absoluteString)")
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if let incomingURL = userActivity.webpageURL {
        print("Incoming URL is \(incomingURL)")
        let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
            guard error == nil else{
                print("Found an error! \(error!.localizedDescription)")
                return
            }
            if let dynamicLink = dynamicLink {
                self.handleIncomingDynamicLink(dynamicLink)
            }
        }
        if linkHandled {
            return true
        } else {
            return false
        }
    }
    return false
}

Any help would be greatly appreciated--is it possible this is a problem with Firebase itself or no?

like image 412
nickcoding Avatar asked Aug 09 '26 07:08

nickcoding


1 Answers

SwiftUI 2.0 / @main App For the new SwiftUI 2.0 you can make an app only using SwiftUI. This means you don't use AppDelegate or SceneDelegate. You then have to use .onOpenURL to get any action called when you click on your link. I am usling this for Firebase Dynamic Links.

WindowGroup {
  ContentView()
    .onOpenURL { url in
      // handle the URL that must be opened
      let incomingURL = url
      print("Incoming URL is: \(incomingURL)")
      let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
          guard error == nil else {
             print("Error found!: \(error!.localizedDescription)")
                return
          }
          if let dynamicLink = dynamicLink {
             self.handleDynamicLink(dynamicLink)
          }
       }
       if linkHandled{
          print("Link Handled")
          return
       }else{
          print("NO linkHandled")
          return
       }
    }
}
like image 89
Kristian Lofthus Avatar answered Aug 11 '26 23:08

Kristian Lofthus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!