在自己的App里面想把文件导出去,使用其它的App打开,查了文档之后,开始写代码,起初使用如下:
- (void)exportFileToOtherApp:(NSString*)filePath
{
NSURL *url = [NSURL fileURLWithPath:filePath];
UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
[documentInteractionController setDelegate:self];
CGRect rect = CGRectMake(self.view.bounds.size.width, 40.0, 0.0, 0.0);
[documentInteractionController presentOpenInMenuFromRect:rect inView:self.view animated:YES];
}
运行起来后,可以弹出来选择程序的窗口,也可以选择App,但是选了App后,就没反应了,文件没导出去,实验来实验去,最后问题终于解决了,原来是:UIDocumentInteractionController *documentInteractionController这个局部变量惹的祸。
把UIDocumentInteractionController *documentInteractionController移到头文件里面,一切正常。
总结下来,应该是把变量定义在了函数里面,结果函数走完,窗口弹出后,变量的生命期结束了,所以再在弹出的窗口里面选择App导出文件,这时变量的内容估计已为空了,所以没有内容可导出。
把变量定义为全局的,就可以了。