无法在iOS 9中与Whatsapp共享文本

时间:2016-05-11 13:06:21

标签: ios objective-c swift

在iOS 8及更低版本上与Whatsapp共享文本时,此代码运行正常,但在iOS 9上共享时无效。

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

2 个答案:

答案 0 :(得分:4)

iOS 9LSApplicationQueriesSchemes需要任何电话,请确保您在.plist添加以下信息:

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

然后尝试

答案 1 :(得分:1)

如果您为iOS 9或更高版本构建,则需要将应用程序将查询的方案列入白名单。

enter image description here