如何以编程方式在Firebase中创建动态链接?迅速 [英] How to create a Dynamic link in Firebase programmatically? Swift

查看:93
本文介绍了如何以编程方式在Firebase中创建动态链接?迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Firebase动态程序,但是在components.shorten

I would like to create a firebase dynamic, but I can't get error in components.shorten

操作无法完成.长链接不可解析.

The operation couldn’t be completed. Long link is not parsable.

我正在关注firebase文档,但可以获得预期的结果.

I am following the firebase docs, but I can get the desired outcome.

 @IBAction func createGroupAction(_ sender: Any) {

    let dynamicLinkDomain = "https://a5481.app.goo.gl/"
    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://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)")
            //prints:
            //error is The operation couldn’t be completed. Long link is not parsable: https://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
            return
        }

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

推荐答案

感谢在注释中包含输出,这使发现错误变得容易.

Thanks for including the output in the comments, that made it easy to spot the errors.

  1. 仅将域包括在动态链接域中,例如let dynamicLinkDomain = "a5481.app.goo.gl"
  2. 要进一步测试:您可以通过在长行的末尾添加& d = 1"来调试长链接,并将其粘贴到浏览器中.

这篇关于如何以编程方式在Firebase中创建动态链接?迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆