Image 如何通过WhatsApp共享图像?

Image 如何通过WhatsApp共享图像?,image,whatsapp,Image,Whatsapp,我正在使用这个代码,但它不起作用,它如何适应它? 有人帮忙吗?谢谢 UIImage *iconImage = [UIImage imageNamed:@"Home01-A01.png"]; NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"]; [UIImageJPEGRepresentation(iconImage, 1.0) writeTo

我正在使用这个代码,但它不起作用,它如何适应它? 有人帮忙吗?谢谢

UIImage  *iconImage = [UIImage imageNamed:@"Home01-A01.png"];

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:CGRectZero inView:self.view animated:YES];

您好,您可以使用UIDocumentationView控制器在WhatsApp上共享您的文件,请执行以下操作以实现相同的目的:

在viewcontroller.h文件中

为添加代理 UIDocumentInteractionControllerDelegate

像这样声明UIDocumentInteractionController对象 UIDocumentInteractionController*控制器

在viewcontroller.m文件中

为UIDocumentationView控制器添加以下委托方法,以跟踪成功和失败的状态

pragma标记-委托方法 添加以下代码以共享您的文件

-(void)openDocument {
    // here's a URL from our bundle
    NSURL *documentURL = [[NSBundle mainBundle]URLForResource:@"chat" withExtension:@"png”];// You can set your filename and extention here

    // pass it to our document interaction controller
    controller = [[UIDocumentInteractionController alloc]init];
    controller.delegate = self;
    controller.URL = documentURL;

    // present the preview
    [controller presentPreviewAnimated:YES];
}
注意:您指定的URL必须是本地的

UIDocumentInteractionController的目标是共享本地文档 在应用程序之间。如果文件未存储在本地,则可以 通过将文件存储在临时或本地缓存目录中,然后从 主束


你能说明什么不起作用吗?你有错误吗?你期待什么,你得到了什么?它没有得到错误,但我按下whatsapp图标,应用程序退出。
-(void)openDocument {
    // here's a URL from our bundle
    NSURL *documentURL = [[NSBundle mainBundle]URLForResource:@"chat" withExtension:@"png”];// You can set your filename and extention here

    // pass it to our document interaction controller
    controller = [[UIDocumentInteractionController alloc]init];
    controller.delegate = self;
    controller.URL = documentURL;

    // present the preview
    [controller presentPreviewAnimated:YES];
}