UIActivityViewController图像分享无法在WhatsApp中使用

11

当我使用UIActivityViewController分享图片数据到Whatsapp应用程序时,会弹出一个警告:

  

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

我能够将图片数据分享到所有其他应用程序,除了Whatsapp之外,是否有人遇到过这样的问题?或者有人能帮助我解决这个问题吗?

如果有人想要检查代码,请发表评论,我会提供需要的代码。


我也遇到了同样的问题,并联系了WhatsApp支持,但迄今为止没有运气,在旧版本中它运行良好,因此我的结论是iOS中WhatsApp的新更新存在一些问题,导致我们无法通过activityItems发布。 - Chetan
1
你曾经能够解决这个bug吗?我在三年后遇到了完全相同的问题。 - Danny Bravo
@DannyBravo 你想分享什么? - iYoung
1个回答

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

2
我正在使用UICollectionViewController。您能告诉我如何检测用户是否点击了WhatsApp并调用此方法吗? - iYoung
你能分享一下你的代码吗?你需要安装最新版本的WhatsApp。同时请说明你测试应用程序的设备配置。 - Abin Koshy Cheriyan
1
这只是分享图片,如果我想同时分享图像和文本,需要做哪些更改? - Zac24

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接