UIDocumentInteractionController OpenInMenu崩溃iOS应用程序

rom*_*eup 12 ios

我正在尝试使用UIDocumentInteractionController OpenIn菜单将我的应用程序中生成的图像发送到其他应用程序.我用这段代码将UIImage保存到磁盘:

    fileJpeg = [NSTemporaryDirectory() stringByAppendingPathComponent:@"activeImage.jpg"];
    jpegFileURL = [NSURL fileURLWithPath:fileJpeg];

    UIImage *imageToWrite = image;

    [UIImageJPEGRepresentation(imageToWrite, 1.0) writeToFile:fileJpeg atomically:YES];
Run Code Online (Sandbox Code Playgroud)

我正在使用MFMailComposeViewController通过电子邮件发送图像的另一种方法访问jpegFileURL,它运行正常,因此NSURL是有效的.但是当我尝试将图像发送到另一个应用程序(只是发送,我没有实现任何预览功能)时,应用程序崩溃了.这是方法:

- (IBAction)openInOtherApp:(id)sender{

UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL: jpegFileURL];
controller.delegate = self;
CGRect rect = self.view.frame;
[controller presentOpenInMenuFromRect:rect inView:self.view animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

显示"打开"菜单.当我点击任何可用应用程序的按钮时,它会崩溃.在iOS6(6.0.1)和iOS5(5.1.1)设备上测试时,我在控制台中没有输出错误(只是通常的EXC_BAD_ACCESS(代码= 1,地址...崩溃),但是在iOS 4.3设备上(应用程序是4.3向上兼容)我在控制台中收到此错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType actionSheet:clickedButtonAtIndex:]: unrecognized selector sent to instance 0x16b7f0'
Run Code Online (Sandbox Code Playgroud)

我一直在阅读关于UIDocumentInteractionController和UIDocumentInteractionControllerDelegate的Apple文档,我在我的类@interface中实现,但似乎不需要任何可选的委托方法来满足我的需求或在此崩溃中有所帮助.

无法想象有什么不对或缺失.任何帮助,将不胜感激.

rom*_*eup 35

发现问题,多亏了这个答案.这是记忆的事情.我使用UIDocumentInteractionController作为本地实例变量,ARC很快将其释放.把它变成了一个类属性,现在一切正常.