我有一个 UIDocumentInteractionController
实例(它确实在我的类中有很强的引用,我知道它的内存问题)并且我想发送一张照片文件到 Instagram。
我使用 ig
扩展名保存了文件(也尝试了 igo
),我正在展示 Controller 。 Instagram 显示在列表中。我点击 Instagram,但没有任何反应。
NSURL *imageFile = [NSURL fileURLWithPath:path];
interactionController = [UIDocumentInteractionController interactionControllerWithURL:imageFile];
interactionController.UTI = @"com.instagram.photo";
interactionController.annotation = [NSDictionary dictionaryWithObject:@"my caption" forKey:@"InstagramCaption"];
interactionController.delegate = self;
[interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
为了进一步调查,我将我的调用类设置为委托(delegate)并实现了 willBeginSendingToApplication:
和 didEndSendingToApplication:
方法。有趣的是,我意识到 willBeginSendingToApplication:
确实会被调用,但 didEndSendingToApplication:
不会。我试过更改我的文件扩展名,将 UTI 更改为 com.instagram.exclusivegram
,检查文件 URL 是否正确等,但它们似乎都不起作用。没有错误,控制台中没有任何内容。交互 Controller 关闭,我的应用程序继续像以前一样工作,只是没有任何反应。我读过 iOS 6 上可能存在一些问题,但我的应用程序是 iOS 6 应用程序,所以我无法在 iOS < 6 上测试它。我发现的唯一接近我的问题的是UIDocumentInteractionController, No File Extension but UTI但它过于深入低级位,我也没有非 ARC 代码。
问题的原因可能是什么?
最佳答案
如果文件不存在,或者您没有正确构建文件 URL,就会发生这种情况。这困扰了我一段时间。
确保像这样构建文件 URL:
NSURL *pagesURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MyGreatPDF.pdf" ofType:nil]];
不是这样的:
NSURL *pagesURL = [NSURL fileURLWithPath:@"MyGreatPDF.pdf"];
后者仍然形成一个有效的 URL,但它有一个“私有(private)”前缀,即 file:///private/var/mobile/Applications/00000000-0000-0000-0000-000000000000/MyGreatApp.app/MyGreatPDF.pdf
而不是 file:///var/mobile/Applications/00000000-0000-0000-0000-000000000000/MyGreatApp.app/MyGreatPDF.pdf
关于ios - UIDocumentInteractionController 不打开应用程序 (didEndSendingToApplication : never called),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16543232/