【问题标题】:WhatsApp image sharing iOS [closed]WhatsApp图像共享iOS [关闭]
【发布时间】:2013-12-23 09:35:48
【问题描述】:

我正在开发一个 iOS 应用程序,我必须从我的应用程序在 WhatsApp 上共享图像。我找到了这段代码,但它只处理文本共享https://github.com/jberlana/JBWhatsAppActivity

【问题讨论】:

标签: ios iphone objective-c whatsapp


【解决方案1】:

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

}

【讨论】:

  • 在这段代码中我们在哪里设置 UIDocumentInteractionController 的 UTI。因为一旦这两行 self.documentationInteractionController.UTI = @"net.whatsapp.image"; self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self];覆盖它
  • 首先使用按钮单击测试此代码
  • @IronMan: self.documentationInteractionController.UTI = @"net.whatsapp.image"; 你正在设置UTI!没有?
  • 实际上我在我的项目中使用了上面的代码,我测试它很好,我可以分享图像。这是工作代码,我不明白你在哪里卡住了
  • 可以通过 UIActivityViewController 进行分享
猜你喜欢
  • 1970-01-01
  • 2017-01-01
  • 2012-12-21
  • 2016-09-28
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多