我正在开发一个iOS应用程序,需要在我的应用程序中通过WhatsApp分享图片。我找到了这段代码,但它只涉及文本共享https://github.com/jberlana/JBWhatsAppActivity
我正在开发一个iOS应用程序,需要在我的应用程序中通过WhatsApp分享图片。我找到了这段代码,但它只涉及文本共享https://github.com/jberlana/JBWhatsAppActivity
可以使用documentationInteractionController
来实现这一点。
最近,我使用以下代码分享了我们应用程序中的图像到WhatsApp、Line和WeChat,但是当您点击WhatsApp图标时,您将从您的应用程序导航到WhatsApp
应用程序,您必须手动返回您的应用程序。在图像共享之后,它不会再次重定向。
在.h文件中:
@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;
}
self.documentationInteractionController.UTI = @"net.whatsapp.image";
,你是在设置 UTI!对吧? - Maulik