UIActivityViewController image share does not work for Whatsapp

When I pass image data to Whatsapp using UIActivityViewController , I get a warning:

This item cannot be used. Select another item.

I can share image data with all other applications except Whatsapp , has anyone encountered such a problem? Or can someone help me solve this problem.

If someone wants to check the code, make a comment if necessary.

+7
ios swift whatsapp uiactivityviewcontroller
source share
1 answer

If you want to share the image using WhatsApp, use the code below:

 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]; } 
+4
source share

All Articles