我正在尝试通过Whatsapp URL方案将Google Maps URL作为文本传递。
我正在尝试对其进行编码,但是我认为我做的不正确。
let message = "View my current location at http://maps.google.com/?q=\(location.coordinate.latitude),\(location.coordinate.longitude)"
var completewhatsappURLString = whatsappURL + message
completewhatsappURLString = completewhatsappURLString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
let completeURL = NSURL(string: completewhatsappURLString)
最佳答案
let mapsURL = "comgooglemaps://?q=\(location.coordinate.latitude),\(location.coordinate.longitude)"
let message = "View my current location at \(mapsURL)" as CFString
let encodedString: String = String(CFURLCreateStringByAddingPercentEscapes(nil, message, nil, "!*'();:@&=+$,/?%#[]" as CFString, CFStringBuiltInEncodings.UTF8.rawValue))
let completewhatsappURLString = "whatsapp://send?text=" + encodedString
let completeURL = NSURL(string: completewhatsappURLString)
if (UIApplication.sharedApplication().canOpenURL(completeURL!)) {
UIApplication.sharedApplication().openURL(completeURL!)
}
关于ios - 通过WhatsApp URL方案将URL作为文本传递,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32142198/