无法从 Firebase 缩短的动态链接网址检索动态链接
Posted
技术标签:
【中文标题】无法从 Firebase 缩短的动态链接网址检索动态链接【英文标题】:Unable to retrieve Dynamic Link from the Firebase shortened dynamic link URL 【发布时间】:2019-11-11 08:25:13 【问题描述】:通过 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 中我使用以下函数来接收这个:
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 动态链接创建的缩短 URL,而不是实际 URL
【问题讨论】:
这里有同样的问题..运气好吗? 【参考方案1】:我遇到了类似的问题,我只是忘记将 FirebaseDynamicLinksCustomDomains
数组添加到我的 Info.plist
中,这就是为什么 firebase 没有从短网址中获取完整网址的原因。
相关文档:https://firebase.google.com/docs/dynamic-links/custom-domains
【讨论】:
【参考方案2】:在示例中,Firebase 从 useractivity.webpageURL
读取 URL。如果您在闭包中阅读来自dynamicLink.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)")
【讨论】:
以上是关于无法从 Firebase 缩短的动态链接网址检索动态链接的主要内容,如果未能解决你的问题,请参考以下文章
我可以使用 Firebase 动态链接作为 URL 缩短器吗?
我无法检索应在 Android 上的意图数据内的 Firebase 动态链接
从 Firebase 动态链接中检索 UTMParameters