3

When sharing text to Whatsapp on iOS 8 and below this code is working fine, but while sharing on iOS 9 it is not working.

- (IBAction)btnWhatsApp:(id)sender {
    NSString *msg = shareText;
    NSString *urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
    NSURL *whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
        [[UIApplication sharedApplication] openURL: whatsappURL];
    }
    else {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }

    [self.tabBarController.tabBar setHidden:NO];
    [viewShare setHidden:YES];
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
PPreeti
  • 201
  • 1
  • 3
  • 10

2 Answers2

4

In iOS 9, LSApplicationQueriesSchemes need for any call, ensure once are you added the following information in youre .plist:

<key>LSApplicationQueriesSchemes</key>
 <array>
  <string>whatsapp</string>
 </array>

then try

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
1

If you build for iOS 9 or above you need to whitelist the schemes your app will query.

enter image description here

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152