Apr*_*ril 3 objective-c ios whatsapp
我正在使用以下代码从我的iOS应用程序分享WhatsApp上的文本.
NSString *textToSend = [NSString stringWithFormat:@"whatsapp://send?text=%@", self.theTextView.text];
NSURL *whatsappURL = [NSURL URLWithString:textToSend];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}else{
[[[UIAlertView alloc] initWithTitle:nil message:@"Whatsapp not isntalled on this device! Please install first." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil]show];
}
Run Code Online (Sandbox Code Playgroud)
这没有按预期工作.
如果我喜欢这里解释它可以正常工作.
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
Run Code Online (Sandbox Code Playgroud)
Matteo Pacini您的回答不正确,
你必须添加PercentEscapes(stringByAddingPercentEscapesUsingEncoding:)NOT REPLACE PercentEscapes(stringByReplacingPercentEscapesUsingEncoding:)
string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3498 次 |
| 最近记录: |