ios - 直接使用 UIDocumentINteractionController 自动打开 WhatsApp,无需显示其他应用程序

标签 ios objective-c image uidocumentinteraction socialshare

我正在开发与其他应用程序共享图像的功能,包括 WhatsApp。 我正在使用这段代码并且它有效。

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){
    UIImage *image = [self processImage:sender];

    NSString *savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

    [UIImageJPEGRepresentation(image, 1.0) writeToFile:savePath atomically:YES];


    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.delegate = self;
    _documentInteractionController.UTI = @"net.whatsapp.image";
    [_documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];


}else {
    [self showAlertTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed."];
}

问题是,当我运行此代码时,documentInteractionController 会显示其他选项应用程序,如 image ,所以我必须先选择WhatsApp,然后才能打开WhatsApp应用程序。

我可以选择Whatsapp App来分享文件而不显示选择菜单吗?换句话说,我可以避免 presentOpenInMenuFromRect 吗?

我使用的是 iOS 9,我的 Instagram 帖子也出现此问题

最佳答案

是的。您可以写 this代码。运行代码后执行以下操作。

步骤1:在Info.plist中添加LSApplicationQueriesSchemes

步骤2:在项目中添加whatsapp。

关于ios - 直接使用 UIDocumentINteractionController 自动打开 WhatsApp,无需显示其他应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911131/

相关文章:

jquery - 移动设备的选择语句

ios - swift promise 套件 : Equivalent to when() which executes sequentially?

ios - 如何为 Uitextfield 设置最小和最大限制?

c# - 使用 WPF 在线程中加载图像

iPhone 无法从 MySQL 下载图像 (BLOB)

ios - Xcode - 我更改了产品模块名称,现在自动完成功能将不再起作用(使用新模块名称时)

ios - UICollectionViewCell 的 UiTextField,在 UICollectionViewController 中重叠

ios - 如何将 int array[] 声明为 appDelegate 中的属性

ios - 需要在 uicollectionview 中显示视频和图像

Java:从二进制数据(图像数据和调色板)创建图像