Whatsapp图像共享无法正常工作

普拉文

我的课程实现,UIDocumentInteractionControllerDelegate并且具有以下属性:@property (nonatomic,retain) UIDocumentInteractionController * documentInteractionController;

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]) {
    UIImage     *iconImage = [UIImage imageNamed:@"bg_iPhone_5.jpg"];
    NSString    *savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

    [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.UTI = @"net.whatsapp.image";
    _documentInteractionController.delegate = self;
    [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
}
else {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

嗨,我已经使用了此代码,但是图像共享无法正常工作。DocumentInteractionController启动带有whatsapp图标的屏幕,当我单击它时,我的应用程序崩溃。

二烯

这是使用正确方法来设置用于写出临时图像的URL的代码:

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]) {
    NSError *error = nil;
    NSURL *documentURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:&error];
    if (!documentURL) {
        NSLog(@"Error getting doucment directory: %@", error);
    }

    NSURL *tempFile = [documentURL URLByAppendingPathComponent:@"whatsAppTmp.wai"];
    UIImage *iconImage = [UIImage imageNamed:@"bg_iPhone_5.jpg"];

    NSData *imageData = UIImageJPEGRepresentation(iconImage, 1.0) ;
    if (![imageData writeToURL:tempFile options:NSDataWritingAtomic error:&error]) {
        NSLog(@"Error writing File: %@", error);
    }

    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:tempFile];
    self.documentInteractionController.UTI = @"net.whatsapp.image";
    self.documentInteractionController.delegate = self;
    [self.documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
}
else {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

图像解密无法正常工作

来自分类Dev

图像滑块无法正常工作

来自分类Dev

图像预览无法正常工作

来自分类Dev

whatsapp共享无法正常工作(同一代码在另一个项目中正常工作)

来自分类Dev

桌面共享在家中无法正常工作

来自分类Dev

与今天扩展共享SQLite无法正常工作

来自分类Dev

WebView App Android中的Whatsapp聊天无法正常工作

来自分类Dev

尝试缩放画布图像无法正常工作

来自分类Dev

来自图像纹理的Physicalbody无法正常工作

来自分类Dev

图像输出无法正常工作的PHP

来自分类Dev

使用BufferedOutputStream写入图像无法正常工作

来自分类Dev

django图像裁剪无法正常工作

来自分类Dev

Django图像上传无法正常工作

来自分类Dev

钛模块图像工厂无法正常工作

来自分类Dev

Colorbox图像显示无法正常工作

来自分类Dev

pyvips图像合成无法正常工作

来自分类Dev

从SVG创建图像无法正常工作

来自分类Dev

图像上的Href无法正常工作

来自分类Dev

尝试前景图像无法正常工作

来自分类Dev

背景图像过渡无法正常工作?

来自分类Dev

加载图像到JPanel无法正常工作

来自分类Dev

图像上的CORS无法正常工作

来自分类Dev

更改图像onclick无法正常工作

来自分类Dev

来自图像纹理的Physicalbody无法正常工作

来自分类Dev

从图像到视频的innerHTML无法正常工作

来自分类Dev

JavaScript图像滑块无法正常工作

来自分类Dev

Bootstrap 图像滑块控件无法正常工作

来自分类Dev

Javascript:图像预览无法正常工作

来自分类Dev

Jquery 图像滑块无法正常工作