通过whatsapp发送文本无效

时间:2014-03-27 05:28:26

标签: actionscript-3 flex flexbuilder whatsapp

我是Flex手机应用程序开发的新手,我想通过whatsapp分享一个文本。这是一些代码。但它不起作用。

navigateToURL(new URLRequest("whatsapp://send?text=Hello how r u???" )
你可以帮助我吗? 提前谢谢。

1 个答案:

答案 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);
}