How Can I share image +text caption(URL) on whatsapp from iphone?

只愿长相守 提交于 2019-12-03 10:39:06

You cannot pre-fill caption while sharing image on whatsapp. Facebook has already deprecated this functionality from Facebook, Instagram also.

You can either send a text or an image. But programmatically pre-filling caption is not possible.

The code in the question is fine to send an image. In order to send a plain text you can use the reference of below mentioned link:

http://www.whatsapp.com/faq/en/iphone/23559013

NOTE: Setting caption programmatically is not possible.

Hope this helps!

user5363247
NSError *error       = nil;
NSURL   *documentURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:&error];

UIImage *image     = [UIImage imageNamed:@"share.png"];
NSURL   *tempFile  = [documentURL URLByAppendingPathComponent:@"whatsAppTmp.wai"];
NSData  *imageData = UIImageJPEGRepresentation(image, 1.0);

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

NSLog(@"%@",docDir);
NSLog(@"saving png");

NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
NSData *data1 = [NSData dataWithData:UIImageJPEGRepresentation(image,1.0)];
[data1 writeToFile:pngFilePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pngFilePath]];
_documentInteractionController.delegate = self;
_documentInteractionController.UTI = @"net.whatsapp.image";

[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!