我已经实现了到IOS应用的firebase动态链接。墨水正在产生,但我想缩短链接以便与社交媒体共享。但是我无法继续生成更短的链接。以下是我用于生成短链接的代码。
//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))")
}
但是,每次结束时都出现以下错误,即“错误是操作无法完成。无法缩短简短的动态链接:”。因此,如何缩短长链接。
答案 0 :(得分:0)
我已经准备了缩短长链接的示例代码,希望对您有所帮助:-
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!))")
})