iYoung
iYoung

Reputation: 3622

UIActivityViewController image share not working for Whatsapp

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.

Upvotes: 11

Views: 2830

Answers (1)

Abin Koshy Cheriyan
Abin Koshy Cheriyan

Reputation: 617

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

Upvotes: 4

Related Questions