在dynamicLinks.handleUniversalLink(url)的回调中接收nil

Azh*_*hir 5 xcode ios firebase swift deeplink

我正在努力接收 firebase 动态链接。在App delegate的restoreHandler方法中,我调用了Firebase DynamicLinks的DynamicLinks.dynamicLinks().handleUniversalLink(url)方法来从短链接中获取实际链接。但在这个方法的回调中,我在动态链接中收到零。因此,我无法从回调中收到的动态链接获取 url。谁能帮我弄清楚为什么它返回零。

func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

        if let incomingURL = userActivity.webpageURL {
// it prints the passed url and working fine
            debugPrint("Imcoing Url is: \(incomingURL.absoluteString)")

            let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in

                guard error == nil else {
                    debugPrint("Error Found: \(error!.localizedDescription)")
                    return
                }
//
//
                if let dynamiclink = dynamicLink, let _ = dynamiclink.url {
// but below function call is not called beacause dynamicLink coming in
// callback is nil
                    self.handleIncomingDynamicLink(dynamiclink)
                }
            }
            if linkHandled {
                return true
            } else {
                // do other stuff to incoming URL?
                return false
            }
        }

        return false
    }
Run Code Online (Sandbox Code Playgroud)

Azh*_*hir 1

我找到了一种方法,在 Swift 中扩展短 URL,以获取短 url 中的实际 url 或查询参数,在我的情况下,这些参数为零,因为我dynamiclink在完成处理程序中收到了

DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in 
    //Both dynamicLink and error were nil here in my case 
}
Run Code Online (Sandbox Code Playgroud)

零。这些代码行将执行相同的操作,以便从短 URL 获取实际 url 或查询参数。

URLSession.shared.dataTask(with: incomingURL) { (data, response, error) in

            if let actualURL = response?.url {

                // you will get actual URL from short link here

                // e.g short url was  
                // https://sampleuniversallink.page.link/hcabcx2fdkfF5U

                // e.g actual url will be  
                // https://www.example.com/somePage?quertItemkey=quertItemvalue...
            }
        }.resume()
Run Code Online (Sandbox Code Playgroud)

  • 这只返回桌面链接,而不返回针对移动设备的链接。 (3认同)