2

我正在开发其他应用程序的共享图像,包括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会显示像此图像这样的其他选项应用程序,因此我必须先选择 WhatsApp,然后才能打开 WhatsApp 应用程序。

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

我正在使用 iOS 9,这个问题也发生在我的 Instagram 帖子中

4

1 回答 1

2

是的。你可以写这段代码。运行代码后执行以下操作。

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

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

于 2016-10-07T08:12:56.113 回答