无法从Firebase缩短的动态链接URL中检索动态链接

时间:2019-11-11 08:25:13

标签: ios swift firebase-dynamic-links

通过WhatsApp打开时,无法从使用Firebase动态链接创建的简短网址中检索动态链接。

通过Skype打开时,它显示预览屏幕,但是当使用WhatsApp单击URL时,它直接打开应用程序而不打开预览屏幕,此后,我无法检索动态链接。 我正在使用以下代码创建并缩短动态链接:

guard let link = URL(string: "https://example.com/abc/\(id)") else { return }
        let dynamicLinksDomainURIPrefix = "https://myexample.online"
        let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix)

        linkBuilder?.iOSParameters = DynamicLinkIOSParameters(bundleID: "bundleID")
        linkBuilder?.iOSParameters?.appStoreID = "appStoreID"
        linkBuilder?.androidParameters = DynamicLinkAndroidParameters(packageName: "packageName")
        linkBuilder?.options = DynamicLinkComponentsOptions()
        linkBuilder?.options?.pathLength = .short

        guard let longDynamicLink = linkBuilder?.url else {
            Alert.HideProgressHud(Onview: self.view)
            return
        }
        DispatchQueue.main.async {

            DynamicLinkComponents.shortenURL(longDynamicLink, options: linkBuilder?.options) { url, warnings, error in
                let url = url
                self.openactivityPickerForSharing(capturedImage: capturedImage, url: url)
            }
        }

在AppDelegate中,我正在使用以下函数o会收到此消息:


        if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
            // Handle the deep link. For example, show the deep-linked content or
            // apply a promotional offer to the user's account.
            // [START_EXCLUDE]
            // In this sample, we just open an alert.
            handleDynamicLink(dynamicLink)
            // [END_EXCLUDE]
            return true
        }
        return application(app, open: url,sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,annotation: "")
    }

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
            // Handle the deep link. For example, show the deep-linked content or
            // apply a promotional offer to the user's account.
            // [START_EXCLUDE]
            // In this sample, we just open an alert.
            handleDynamicLink(dynamicLink)
            // [END_EXCLUDE]
            return true
        }
        // [START_EXCLUDE silent]
        // Show the deep link that the app was called with.
        //showDeepLinkAlertView(withMessage: "openURL:\n\(url)")
        // [END_EXCLUDE]
        return false
    }
    // [END openurl]
// [START continueuseractivity]
    func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
            // [START_EXCLUDE]
           //self.showDeepLinkAlertView(withMessage: "\(dynamiclink)")
            // [END_EXCLUDE]
        }
//handled is always returned always
        // [START_EXCLUDE silent]
        if !handled {
           //Handled the URL received in Case of Skype.
        }
        // [END_EXCLUDE]
        return handled
    }

 func handleDynamicLink(_ dynamicLink: DynamicLink) {
        let matchConfidence: String
        if dynamicLink.matchType == .weak {
            matchConfidence = "Weak"
        } else {
            matchConfidence = "Strong"
        }
        let message = "App URL: \(dynamicLink.url?.absoluteString ?? "")\n" +
        "Match Confidence: \(matchConfidence)\nMinimum App Version: \(dynamicLink.minimumAppVersion ?? "")"
    }

此后,当我单击WhatsApp上共享的缩短的URL时,我收到的URL是Firbase Dynamic Links创建的缩短的URL,而不是实际的URL。

2 个答案:

答案 0 :(得分:1)

我遇到了类似的问题,我只是忘记向我的FirebaseDynamicLinksCustomDomains中添加Info.plist数组,这就是为什么firebase无法从短文本中获取完整URL的原因。

相关文档:
https://firebase.google.com/docs/dynamic-links/custom-domains

答案 1 :(得分:0)

在示例中,Firebase从useractivity.webpageURL读取URL。如果您要从封闭中的dynamicLink.url中读取URL,则会看到原始的动态链接。

func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                 restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in

      print("This is the full length url: \(dynamiclink.url)")
    }
}