简体   繁体   English

Firebase 动态链接未打开应用程序 iOS 14

[英]Firebase dynamic link not opening app iOS 14

I am attempting to create dynamic links to work as part of a referral system for my app.我正在尝试创建动态链接以作为我的应用程序推荐系统的一部分。 I believe I am successfully creating the links, however whenever I click on one from my notes app while running my app (which I am told should just open the app) I am directed to a Safari page then the App Store.我相信我成功地创建了链接,但是每当我在运行我的应用程序时从我的笔记应用程序中单击一个(我被告知应该只打开应用程序),我都会被定向到 Safari 页面,然后是 App Store。 This leads me to beleive the dynamic like for whatever reason isn't being handled at all by my app.这让我相信无论出于何种原因,我的应用程序根本没有处理动态。

I am using a custom domain URI prefix, specifically https://mywebsite.com/invite and here is the complete code for creating my dynamic link我正在使用自定义域 URI 前缀,特别是https://mywebsite.com/invite ,这是创建动态链接的完整代码

            guard let uid = Auth.auth().currentUser?.uid else {return}
            let link = URL(string: "https://mywebsite.com/invite/?invitedby=\(uid)")
            let referralLink = DynamicLinkComponents(link: link!, domainURIPrefix: "https://mywebsite.com/invite")
            
            referralLink?.iOSParameters = DynamicLinkIOSParameters(bundleID: "myBundleId")
            referralLink?.iOSParameters?.minimumAppVersion = "1.0"
            referralLink?.iOSParameters?.appStoreID = "123456789"
            
            referralLink?.shorten { (shortURL, warnings, error) in
                guard let referURL = shortURL else {
                    Service.showAlert(on: self, style: .alert, title: "Link Error", message: "We were unable to retreive your referral link at this time.")
                    return
                }
                let activityVC = UIActivityViewController(activityItems: [referURL], applicationActivities: nil)
                UIApplication.shared.windows.first?.rootViewController?.present(activityVC, animated: true, completion: nil)
            }

My code that I took from the Firebase documentation that allegedly is intended to handle the incoming dynamic link is as follows.我从据称旨在处理传入动态链接的 Firebase 文档中获取的代码如下。

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
        return application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: "")
    }
    
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamicLink, error) in
            if (dynamicLink != nil) && !(error != nil) {
                self.handleDynamicLink(dynamicLink)
            }
        }
        return handled
    }

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
            return handleDynamicLink(dynamicLink)
        }
        return false
    }

In addition to my code, I have ensured that in my info.plist I have listed "https://mywebsite.com/invite" under FirebaseDynamicLinksCustomDomains keys, I have added my apps bundle as a URL Type, and have added applinks:mywebsite.com to my apps Associated Domains.除了我的代码之外,我还确保在我的 info.plist 中,我在 FirebaseDynamicLinksCustomDomains 键下列出了“https://mywebsite.com/invite”,我已将我的应用程序包添加为 URL 类型,并添加了 applinks:mywebsite .com 到我的应用关联域。

I have checked multiple other posts and I'm not quite sure what is going wrong here.我检查了多个其他帖子,但我不太确定这里出了什么问题。 If someboyd could shed some light on any potential issues that would be great.如果 someboyd 可以阐明任何潜在的问题,那就太好了。

You are creating link wrong.您创建的链接错误。

You need to set up:您需要设置:

let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: "Firebase short link goes here") let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: "Firebase short link goes here")

let iOSParams = DynamicLinkIOSParameters(bundleID: "IOS app bundle id goes here")让 iOSParams = DynamicLinkIOSParameters(bundleID: "IOS app bundle id 放在这里")

iOSParams.customScheme = "url scheme" // for ios // forandroid firebase have different property iOSParams.customScheme = "url scheme" // for ios // forandroid firebase 有不同的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM