2015-04-28 43 views
0

我想与WhatsApp的api共享图像和文本,但我无法做到。分享图像我有这样的代码:分享图像蚂蚁文本WhatsApp api iOS

if([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]) 
{ 
    NSURL *documentURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; 
    NSURL *tempFile = [documentURL URLByAppendingPathComponent:@"whatsAppTmp.wai"]; 
    NSData *imageData = UIImageJPEGRepresentation(imageFinal, 1.0); 
    [imageData writeToURL:tempFile options:NSDataWritingAtomic error:nil]; 

    documentController = [UIDocumentInteractionController interactionControllerWithURL:tempFile]; 
    documentController.UTI = @"net.whatsapp.image"; 
    documentController.delegate = self; 

    [documentController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES]; 
} 

这工作正常,但我没有找到方法与此图像共享一个文本。我已经找到了如何共享与Instagram的同一表格中的文字,就像

documentController.annotation = @{@"InstagramCaption": "text"}; 

,但它不会成为在WhatsApp的分享图像,我不知道我在用什么键那个字典。我知道在Android中这可以用Intent和额外的EXTRA_TEXT来完成,所以我猜在iOS中也是可以的。

任何人都可以帮助我吗?

谢谢大家。

回答

2

您将无法在whatsapp中同时共享文本和图像。

如果你想分享的文字,你可以做到这一点 -

NSString * mymsg = @"this is test message"; 
NSString * urlString = [NSString stringWithFormat:@"whatsapp://send?text=%@",mymsg]; 
NSURL * url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
if ([[UIApplication sharedApplication] canOpenURL: url]) { 
    [[UIApplication sharedApplication] openURL: url]; 
} else { 
    //show alert 
} 
+2

哦,太可惜了。令人惊讶的是,在Android中,我们可以同时共享这两者,但在iOS中我们无法做到,但这就是事情的原因:(谢谢你的回答。 –