我是Flex手机应用程序开发的新手,我想通过whatsapp
分享一个文本。这是一些代码。但它不起作用。
navigateToURL(new URLRequest("whatsapp://send?text=Hello how r u???" )
你可以帮助我吗?
提前谢谢。
答案 0 :(得分:0)
试试这段代码。应该完美地工作。
-(void)whatsapp{
NSString *massage = [self stringByEncodingString:@"Your massage"];
NSString *urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",massage];
NSURL *whatsappURL = [NSURL URLWithString:urlWhats];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has to have WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
-(NSString *)stringByEncodingString:(NSString *)string{
CFStringRef encodedString = CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)string, NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
return CFBridgingRelease(encodedString);
}