【发布时间】:2013-12-23 09:35:48
【问题描述】:
我正在开发一个 iOS 应用程序,我必须从我的应用程序在 WhatsApp 上共享图像。我找到了这段代码,但它只处理文本共享https://github.com/jberlana/JBWhatsAppActivity
【问题讨论】:
标签: ios iphone objective-c whatsapp
我正在开发一个 iOS 应用程序,我必须从我的应用程序在 WhatsApp 上共享图像。我找到了这段代码,但它只处理文本共享https://github.com/jberlana/JBWhatsAppActivity
【问题讨论】:
标签: ios iphone objective-c whatsapp
使用documentationInteractionController 可以做到这一点。
最近我使用下面的代码将图像从我们的应用程序共享到whatsApp、Line、WeChat,但是当你点击WhatsApp图标时,你会从你的应用程序导航WhatsApp应用程序,你必须手动返回你的应用程序。这不会在 ImageSharing 之后再次重定向。
在 .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!没有?