如何以编程方式创建 Firebase Dynamic Link (iOS)?

How to create a Firebase Dynamic Link programmatically (iOS)?

我通读了所有可用的文档并尝试了 Firebase 示例代码,但似乎没有任何效果。

我已经通过控制台设置了动态 Link,它工作正常。

有人可以向我解释如何创建最基本的动态 link 以便用户可以,例如可以发送 link 直接指向他的个人资料吗?哪些是所需的最少组件?

(如果有人可以 post Objective-C 中的基本代码,那就太好了)

此页面对您有帮助吗https://firebase.google.com/docs/dynamic-links/ios/create? 您可以在 https://github.com/firebase/quickstart-ios/tree/master/dynamiclinks

找到示例代码

我假设你想发送一些键值对,你的 URL 正文中的字典。
下面是如何编写它 .
所以第一步是创建 URL.
接下来,您可以手动 https://firebase.google.com/docs/dynamic-links/create-manually
编写您的 firebase 动态 link 您还可以在 https://firebase.googleblog.com/2017/06/making-dynamic-links-easier.html

找到一个小教程
 @IBAction func createGroupAction(_ sender: Any) {

    let dynamicLinkDomain = "a5481.app.goo.gl"  // <- don't add https scheme to this string
    let appBundleID = "com.vividapartments.myStr.com"

    let params:[String : String] = [
        "ibi": appBundleID,
        "isi": "1222420082",
        "efr":"1",
        "groupID":"-LDSfWKKbWjyrXiFljT3",
        "chatID":"-LDSfWKMbm9mSE2a6EIe"
    ]

    // general link params
    let urlParams = params.flatMap ({ (key,value) -> String in
        return "\(key)=\(value)"
    }).joined(separator: "&")


    guard let deepLink = URL(string:"https://www.mystr.com/groups?\(urlParams)") else {return}

    print("deepLink is \(deepLink)")
    //prints:
    //deepLink is https://www.mystr.com/groups?isi=1222420082&chatID=-LDSfWKMbm9mSE2a6EIe&efr=1&ibi=com.vividapartments.myStr.com&groupID=-LDSfWKKbWjyrXiFljT3

    let components = DynamicLinkComponents(link: deepLink, domain: dynamicLinkDomain)

    let iOSParams = DynamicLinkIOSParameters(bundleID: appBundleID)
    iOSParams.minimumAppVersion = "1.5"
    components.iOSParameters = iOSParams

    //1. Build the dynamic long link
    let longlLink = components.url
    print("The long link is \(longlLink!)")
    //prints:
     //The long link is https://a5481.app.goo.gl/?link=https%3A%2F%2Fwww%2Emystr%2Ecom%2Fgroups%3Fisi%3D1222420082%26chatID%3D%2DLDSfWKMbm9mSE2a6EIe%26efr%3D1%26ibi%3Dcom%2Evividapartments%2EmyStr%2Ecom%26groupID%3D%2DLDSfWKKbWjyrXiFljT3&ibi=com%2Evividapartments%2EmyStr%2Ecom&imv=1%2E5

    //Set the length of a short Dynamic Link
    let options = DynamicLinkComponentsOptions()
    options.pathLength = .unguessable
    components.options = options

    //2. Or create a shortened dynamic link
    components.shorten { (shortURL, warnings, error) in
        if let error = error {
            print("error is \(error.localizedDescription)")
            return
        }

        // TODO: Handle shortURL.
        print("shortURL is \(String(describing: shortURL))")
    }



}

以下代码 100% 适合我。请试一次。

 guard let link = URL(string: "Write your link here and parameters") else { return }
    let dynamicLinksDomainURIPrefix = "https://racematesios.page.link" //domain-link
    let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix )

    linkBuilder!.iOSParameters = DynamicLinkIOSParameters(bundleID: "Bundle ID")
    linkBuilder!.iOSParameters?.appStoreID = "App store ID"

    guard let longDynamicLink = linkBuilder?.url else { return }
    print("The long URL is: \(longDynamicLink)")

请交叉检查相关域:(它不能包含 http 或 https,例如 applinks:myapp。page.link)。动态 link 很容易在 iOS 上工作模拟器,我没有遇到任何问题。