1

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.

ketan
  • 19,129
  • 42
  • 60
  • 98
Sharath Kumar
  • 145
  • 3
  • 4
  • 11

1 Answers1

0

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);
}
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
Yossi
  • 2,525
  • 2
  • 21
  • 24