0

I am to add an image and some text in whatsapp with the help of coding. How can I perform it to solve my problem?

1 Answers1

4

You can post Image or Text on WhatsApp. But you wont post both at a time becouse whatsapp not provide any API that you can add caption and post image with text.

Following is an example for posting image from iPhone app to whatsapp as par WhatsApp Documentation:

in ViewController.h file:

@interface ViewController : UIViewController
{
}

@property(nonatomic,retain) UIDocumentInteractionController *documentationInteractionController;

in ViewController.m file:

- (IBAction)bocClick:(UIButton *)sender {


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"]; //here i am fetched image path from document directory and convert it in to URL and use bellow


    NSURL *imageFileURL =[NSURL fileURLWithPath:getImagePath];
    NSLog(@"imag %@",imageFileURL);

    self.documentationInteractionController.delegate = self;
    self.documentationInteractionController.UTI = @"net.whatsapp.image";
    self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self];
    [self.documentationInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];


}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL

                                               usingDelegate: (id ) interactionDelegate {



    self.documentationInteractionController =

    [UIDocumentInteractionController interactionControllerWithURL: fileURL];

    self.documentationInteractionController.delegate = interactionDelegate;



    return self.documentationInteractionController;

}
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144