UIActivityViewController图像共享不适用于Whatsapp

时间:2015-07-04 07:57:58

标签: ios swift uiactivityviewcontroller whatsapp

当我使用UIActivityViewControllerWhatsapp应用分享图片数据时,我收到提醒信息:

  

此项目无法共享。请选择其他项目。

我可以将图片数据分享给除{{1}}以外的所有其他应用,是否有人遇到过此类问题?或者任何人都可以帮我解决这个问题。

如果有人想检查代码,那么评论会在需要时分享。

1 个答案:

答案 0 :(得分:4)

如果您想使用WhatsApp分享图片,请使用以下代码:

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){

        UIImage     * iconImage = [UIImage imageNamed:@"my_account.png"];
        NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

        [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

        _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
        _documentInteractionController.UTI = @"net.whatsapp.image";
        _documentInteractionController.delegate = self;

        [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];


    } else {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }