Sending text via whatsapp is not working

717 Views Asked by At

I am new to flex mobile app development, I wanna share a text via whatsapp. Here is some code.But its not working.

navigateToURL(new URLRequest("whatsapp://send?text=Hello how r u???" )

Can u please help me. Thanks in advance.

1

There are 1 best solutions below

0
Yossi On

Try this code. Should work perfectly.

-(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);
}