简体   繁体   中英

Firebase Dynamic links

I have implemented a firebase dynamic link to an IOS app. The ink is generating but I want to shorten the link in order to share with social media. But I couldn't proceed with generating a shorter link. The following is the code I'm using for to generate the short link.

    //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))")
    }

But every time it's ended up with the following error which is "error is The operation couldn't be completed. Cannot shorten a short Dynamic Link:". Therefore how to short the long link.

I have prepared the sample code which shorten the long link, hope may help you :-

        guard let link = URL(string: "https://www.hackingwithswift.com/articles/77/whats-new-in-swift-4-2") else { return }
        let dynamicLinksDomainURIPrefix = "https://xyz.page.link" //Your URL prefix added in Dynamic Links section on Firebase
        let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix)
        linkBuilder?.shorten(completion: { (url, warnings, error) in
            if let error = error {
                print("error is \(error.localizedDescription)")
                return
            }
           print("The short URL is: \(String(describing: url!))")
        })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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