我有UIDocumentInteractionController
个实例( DOES 在我的课程中有强大的参考,我知道有关它的内存问题)我想向Instagram发送一个照片文件
我使用ig
扩展程序保存了文件(也尝试了igo
)并且我正在呈现控制器。 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];
为了进一步调查,我将我的调用类设置为委托,并实现了willBeginSendingToApplication:
和didEndSendingToApplication:
方法。有趣的是,我已经意识到willBeginSendingToApplication:
会被调用,但didEndSendingToApplication:
却没有。我已经尝试更改我的文件扩展名,将UTI更改为com.instagram.exclusivegram
,检查文件URL是否正确等等,但它们似乎都不起作用。没有错误,控制台中没有任何东西。交互控制器关闭,我的应用程序保持工作,因为它以前工作,没有任何反应。我已经读过iOS 6上可能存在一些问题,但我的应用程序是iOS 6应用程序,所以我无法在iOS上测试它< 6.我发现的唯一与我的问题相近的是UIDocumentInteractionController, No File Extension but UTI,但它在低级别的位中潜入太多,而且我没有非ARC代码。
问题可能是什么原因?
答案 0 :(得分:5)
如果文件不存在,可能会发生这种情况,但如果您还没有正确构建文件URL,也会发生这种情况。这困扰了我一段时间。
确保构建文件网址如下:
NSURL *pagesURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MyGreatPDF.pdf" ofType:nil]];
而不是这样:
NSURL *pagesURL = [NSURL fileURLWithPath:@"MyGreatPDF.pdf"];
后者仍然会形成一个有效的网址,但它会获得一个"私有"前缀,即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
答案 1 :(得分:1)
过了一会儿,我发现文件没有正确保存,并且不存在。 iOS没有抛出任何类型的错误,无声地失败。我已经更正了有关生成文件的代码,当文件存在时,控制器出现了。也许Apple应该添加一些断言/异常机制来处理文档交互控制器中不存在的文件。
答案 2 :(得分:0)
这也可能是由文件名的扩展名引起的。
如果目标应用在 Info.plist - >中声明它只支持带 png 扩展名的文件。导出的类型UTI - >等效类型 - > public.filename-extension ,并且您发送的文件扩展名为 jpg ,目标应用也不会打开。