iOS Firebase Dynamic link not handled on cold start iOS 14

Viewed 1545

When opening dynamic links on my device, my function in SceneDelegate that handles dynamic links runs fine while the app is running in the background but not when the app is completely shut off. When I do click the dynamic link while the app is off, the app opens but the dynamic link is not handled. My scene delegate function looks like this:

SceneDelegate Function

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    guard let _ = (scene as? UIWindowScene) else { return }

    
    if let incomingURL = userActivity.webpageURL {
        print("Incoming URL is \(incomingURL)")
        _ = 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)
            }
        }
    }
}

any help understanding this issue is greatly appreciated!

2 Answers

Since your target is iOS 14 , You can use latest APIs, So you can use .onOpenURL() modifier on any view.

.onOpenURL { url in
        
        _ = DynamicLinks.dynamicLinks().handleUniversalLink(url) { (dynamicLink, error) in
            guard error == nil else{
                print("Found an error! \(error!.localizedDescription)")
                return
            }
            if let dynamicLink = dynamicLink {
                self.handleIncomingDynamicLink(dynamicLink)
            }
        }
    }

I was having the same issue, but I used the solution proposed from @Yodagama and it works totally fine. In my case I am loading a firebase dynamic link. The only problem I am facing is that if the user doesn't have the app installed, the link first redirects you to apple store to download it and once you have it you have to open the link again in order to perform the function.

I am putting my code here, hope it helps somebody:

import SwiftUI
import Firebase

 @main
 struct Universal_Link_SwiftUI2_0App: App {

init() {
  FirebaseApp.configure()
}

var body: some Scene {
    
    WindowGroup {
        ContentView().onOpenURL { url in
            
            _ = DynamicLinks.dynamicLinks().handleUniversalLink(url) { (dynamicLink, error) in
                guard error == nil else{
                    print("Found an error! \(error!.localizedDescription)")
                    return
                }
                if let dynamicLink = dynamicLink {                         
                    self.handleIncomingDynamicLink(dynamicLink)
                }
            }
        }
     }
   }
Related