11

When I am sharing an image data to Whatsapp app using UIActivityViewController I am getting an alert saying:

This item cannot be shared. Please select a different item.

I am able to share the image data to all other apps except Whatsapp, does anyone has faced such an issue? Or can anyone help me to solve this issue.

If anyone wants to check the code, then do comment will share if required.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
iYoung
  • 3,596
  • 3
  • 32
  • 59
  • Even I am facing the same issue and contact with whatsapp support but no luck so far, in older version it was working fine so my conclusion is that new update of whatsapp in iOS having some problem due to which we are not able to post through activityItems. – Chetan Apr 25 '16 at 13:07
  • 1
    Where you ever able to get around this bug. I am experiencing the exact same issue 3 years later. – Danny Bravo Mar 25 '18 at 07:33
  • @DannyBravo What are you trying to share? – iYoung Mar 26 '18 at 09:55

1 Answers1

4

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

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
    I am using a UICollectionViewController. Can you please tell me that how can I detect that user has clicked whats app & I can call this method. – iYoung Jul 10 '15 at 05:24
  • Can you share your code. You need to have the latest version of WhatsApp also. Also specify the device configuration you are testing your app. – Abin Koshy Cheriyan Aug 31 '15 at 09:36
  • 1
    This is only sharing image, If I want to share Image and text both then what changes I need to make. – Zac24 Sep 10 '15 at 12:22