3

The dynamic links used to be working fine both on actual device, and also in the simulator. When I click on the link in the simulator (or pasting it in safari), I get redirected to the ".page.link" site where it says "open" - and clicking open opens the app perfectly. However, if I repeat the same steps on my actual device, I get redirected to the support url, and nothing happens (app doesn't open even though its installed on my phone).

This is my code in where I display a url

if let uid = Auth.auth().currentUser?.uid {
            guard let link = URL(string: "https://www.testapp.com/uid=" + uid) else {
                return
            }
            let dynamicLinksDomain = "testapp.page.link"
            let linkBuilder = DynamicLinkComponents(link: link, domain: dynamicLinksDomain)
            linkBuilder.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.burgertralla.theGreat")
            linkBuilder.shorten { (url, _, _) in
                if let url = url {
                  self.shareTopLabel.text = url.absoluteString
                }
            }
        }

And this is my AppDelegate:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
            self.handleIncomingDynamicLink(dynamicLink: dynamicLink)
            return true
        }
        return false
    }

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        if let incomingUrl = userActivity.webpageURL {
            let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingUrl, completion: { (dynamicLink, _) in
                if let dynamicLink = dynamicLink, let _ = dynamicLink.url {
                    self.handleIncomingDynamicLink(dynamicLink: dynamicLink)
                }
            })

            if linkHandled {
                return linkHandled
            }
        }
        return false
    }

    func handleIncomingDynamicLink(dynamicLink: DynamicLink) {
        guard let pathComponents = dynamicLink.url?.pathComponents else {
            return
        }
        for pathComponent in pathComponents {
            if pathComponent.contains("uid=") {
                let uid = pathComponent.drop(prefix: "uid=")
                Database.database().reference(withPath: "profile/" + uid).observeSingleEvent(of: .value) { (snapshot) in
                    if snapshot.exists(), var data = snapshot.value as? [String: Any] {
                        data["uid"] = snapshot.key
                        let userProfileVC = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "UserProfileViewController") as! UserProfileViewController
                        if let tabBarVc = self.window?.rootViewController as? UITabBarController {
                            tabBarVc.selectedIndex = 1
                            if let discoveryVC = tabBarVc.viewControllers?[1] as? UINavigationController {
                                userProfileVC.selectedUser = data
                                discoveryVC.pushViewController(userProfileVC, animated: true)
                            }
                        }
                    }
                }
            }
        }
    }

Do anyone have any clue on whats going on here?

Thanks for the help guys :)

EDIT : It does work on my iPhone with Chrome, however not with Safari. I don't know why...

KENdi
  • 7,576
  • 2
  • 16
  • 31
Matt Gilbert
  • 113
  • 1
  • 13
  • https://stackoverflow.com/questions/37724415/firebase-dynamic-link-not-opening-the-app-ios – Popmedic Feb 03 '19 at 21:14
  • 1
    @Popmedic Thanks, that led me to downloading chrome on my iPhone, and the link works on my device with chrome. However it does not work with Safari... (i read the question on stackoverflow, but nothing there seems to work) – Matt Gilbert Feb 03 '19 at 21:25
  • 1
    Did you get anywhere with this? We're seeing the same issue. Works with Safari on Simulator, but not with Safari on physical device (didn't try Chrome). – Luke Pighetti Feb 03 '20 at 20:47
  • 2
    Seeing the same issue when trying to open app with dynamic link. It works fine in simulator but redirects to Safari on real device with Invalid Dynamic Link page – tapizquent Apr 06 '20 at 22:45

0 Answers0