WhatsApp图像共享iOS

8

请参考此链接:http://www.whatsapp.com/faq/en/iphone/23559013 - Parth Bhatt
1个回答

8

可以使用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;

}

在这段代码中,我们在哪里设置UIDocumentInteractionController的UTI呢?因为一旦这两行代码self.documentationInteractionController.UTI = @"net.whatsapp.image"; self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self]; 被覆盖,就无法再进行设置了。 - IronMan
请先使用按钮点击事件测试此代码。 - Nitin Gohel
1
@IronMan:通过这个代码 self.documentationInteractionController.UTI = @"net.whatsapp.image";,你是在设置 UTI!对吧? - Maulik
2
UIActivityViewController能否通过共享功能实现? - IronMan
@NitinGohel 我不确定它是如何工作的。我知道url scheme是如何工作的。这是相同的吗?还是它是一些内部功能。在你的情况下,应用程序会打开WhatsApp吗? - Matrosov Oleksandr
显示剩余7条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接