Reputation: 41
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.
Upvotes: 0
Views: 1255
Reputation: 194
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!))")
})
Upvotes: 2