我正在开发一个iOS应用程序,我必须从我的应用程序在WhatsApp上共享图像。我找到了此代码,但它仅处理文本共享https://github.com/jberlana/JBWhatsAppActivity
答案 0 :(得分:8)
使用documentationInteractionController
可能是可能的。
最近我使用下面的代码来共享图像从我们的应用程序到whatsApp,Line,WeChat但是当你点击WhatsApp图标时,你就是你应用程序的导航WhatsApp
应用程序,你必须手动返回你的应用程序。在ImageSharing之后,它不再重定向。
: -
@interface ViewController : UIViewController<UIDocumentInteractionControllerDelegate>
{
}
@property(nonatomic,retain) UIDocumentInteractionController *documentationInteractionController;
.m文件中的
- (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 <UIDocumentInteractionControllerDelegate>) interactionDelegate {
self.documentationInteractionController =
[UIDocumentInteractionController interactionControllerWithURL: fileURL];
self.documentationInteractionController.delegate = interactionDelegate;
return self.documentationInteractionController;
}