2

I need to share both image and text directly to the WhatsApp. I tried with actionsheet and UIDocumentIntractionController.

I tried with this code:

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){
 [AdDetailsViewController processImageDataWithURLString:self.strThumbImage andBlock:^(NSData *imageData) {

            self.watsappShareimg = [[UIImage alloc]initWithData:imageData];

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

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

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

        [self.documentationInteractionController 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];
    }

Thank u in advance

Kory Gill
  • 6,993
  • 1
  • 25
  • 33
Manju S
  • 21
  • 1
  • 6

1 Answers1

3

You can use UIActivityViewController to share image , text or URL .This is Apple By default share Method

NSString *shareText = @"This is Sharable text";
UIImage * image = [UIImage imageNamed:@"Test.png"];

NSArray *array_Object = @[shareText, image];

UIActivityViewController *obj_activity = [[UIActivityViewController alloc] initWithActivityItems:array_Object applicationActivities:nil];


[self presentViewController:controller animated:YES completion:nil]

You can try above Code But https://www.whatsapp.com/faq/en/iphone/23559013 On This Link They have Mentioned that only Independent text is shared. For Image ,audio ,Video use DocumentationController.

Rohit Khandelwal
  • 1,778
  • 15
  • 23
Narendra Pandey
  • 377
  • 9
  • 28