我刚刚将我的swift项目升级为swift 3.
我一直在使用以下功能在Whatsapp上分享应用,但我无法理解升级后发生的错误
这是功能代码:
func shareOnWhatsapp() {
let urlString = "Greetings,\n\nThis is the XYZ App link, I hope you find it useful!\n\nhttp://itunes.apple.com/app/idxxxxxxxx"
let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed())
let url = URL(string: "whatsapp://send?text=\(urlStringEncoded!)")
if UIApplication.shared.canOpenURL(url!) {
UIApplication.shared.openURL(url!)
}
}
错误说:
Contextual member 'urlHostAllowed' has no associated value
知道如何解决这个问题吗?
答案 0 :(得分:5)
你需要摆脱"()"在第三行:
let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed())
到此:
let urlStringEncoded = urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)