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
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)
}
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 }
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.