简体   繁体   中英

Passing a URL as text through the WhatsApp URL Scheme

I am trying to pass a Google Maps URL as the text through the Whatsapp URL scheme.

I am trying to encode it but I don't think I'm doing it right.

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM