Sport
Sport

Reputation: 8945

Swift Firebase Dynamic Links: shortenURL not working

facing some issue to generate shortenURL from firebase dynamic-links , I am able to get longDynamicLink url . but

here is my code , I am using https://firebase.google.com/docs/dynamic-links/ios/create following steps DynamicLinkComponents.shortenURL completion not getting call and there is no error also

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

DynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { url, warnings, error in
    guard let url = url, error != nil else { return }
    print("The short URL is: \(url)")
}

DynamicLinkComponents.shortenURL this part is not executing

Upvotes: 1

Views: 2824

Answers (2)

Yogesh Tandel
Yogesh Tandel

Reputation: 1754

  1. Add this to to App Capabilities - Associated Domains and enter - applinks:yourdomain.com

enter image description here

  1. In your ViewController add

    guard let link = URL(string: "https://www.yourdomain.com/share_location.html?Id=\(RandomID)&uid=\(uid)") else { return }
        let dynamicLinksDomain = "yourdomain.page.link"
    
    
        let components = DynamicLinkComponents(link: link, domain: dynamicLinksDomain)
        // [START shortLinkOptions]
        let options = DynamicLinkComponentsOptions()
        options.pathLength = .unguessable
        components.options = options
        // [END shortLinkOptions]
    
        // [START shortenLink]
        components.shorten { (shortURL, warnings, error) in
            // Handle shortURL.
            if let error = error {
                print(error.localizedDescription)
                return
            }
            print(shortURL?.absoluteString ?? "")
            self.shortLink = shortURL
        }
    

Upvotes: 0

Dixit Akabari
Dixit Akabari

Reputation: 2547

Try This Code. This Code Working Fine For Me.

    let shareLink:String = "http://YourURL"

    guard let newSharelink = URL(string: shareLink) else { return }
    let components = DynamicLinkComponents.init(link: newSharelink, domain: "Your Domin From Genrated By Google Account(EX. = napu4u.app.goo.gl)")
    let iOSParams = DynamicLinkIOSParameters(bundleID: "YourBundle ID")
    iOSParams.appStoreID = "Your AppStore ID (Optional)"

    components.iOSParameters = iOSParams
    let options = DynamicLinkComponentsOptions()
    options.pathLength = .short
    components.options = options

    components.shorten { (shortURL, warnings, error) in

        if let error = error {
            print(error.localizedDescription)
            return
        }

        let shortLink = shortURL
        print(shortLink)
    }

Upvotes: 5

Related Questions