Objective c 下载ePub(NSURLConnection),保存并使用UIDocumentInteractionController打开它

Objective c 下载ePub(NSURLConnection),保存并使用UIDocumentInteractionController打开它,objective-c,Objective C,所以我尝试下载一本带有NSURLConnection的ePub书籍。到目前为止,下载效果很好。当我试图保存并打开它时,问题就出现了。当我试图用UIDocumentInteractionController打开它时,应用程序崩溃,说目录为空 这是我的密码: //Download ePub file NSURL *url = [NSURL URLWithString:@"http://www.terceiroanjo.com/materiais/missaopiloto.epub"]; NSU

所以我尝试下载一本带有NSURLConnection的ePub书籍。到目前为止,下载效果很好。当我试图保存并打开它时,问题就出现了。当我试图用UIDocumentInteractionController打开它时,应用程序崩溃,说目录为空

这是我的密码:

 //Download ePub file
 NSURL *url = [NSURL URLWithString:@"http://www.terceiroanjo.com/materiais/missaopiloto.epub"];
 NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
 connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
然后

打开电子商务中心:

 NSString *path = [[NSBundle mainBundle] pathForResource:@"missaopiloto" ofType:@"epub"];
 NSURL *urls = [NSURL fileURLWithPath:path];

 self.documentController = [UIDocumentInteractionController interactionControllerWithURL:urls];
 documentController.delegate = self;

 [documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
当我试图打开它时,应用程序崩溃:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*-[NSURL initFileURLWithPath::nil字符串参数”

我明白了,目录是零,但为什么?我做错了什么。有什么想法吗


谢谢。

我认为这里的问题是,一旦下载并保存文件,它就不会成为捆绑包的一部分

如果要访问该文件,必须提供本地路径并创建本地URL

NSString  *path = [NSString stringWithFormat:@"%u/%@", NSDocumentDirectory,@"missaopiloto.epub"];
NSURL *urls = [NSURL fileURLWithPath:path];

self.documentController = [UIDocumentInteractionController interactionControllerWithURL:urls];
documentController.delegate = self;

[documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
NSString  *path = [NSString stringWithFormat:@"%u/%@", NSDocumentDirectory,@"missaopiloto.epub"];
NSURL *urls = [NSURL fileURLWithPath:path];

self.documentController = [UIDocumentInteractionController interactionControllerWithURL:urls];
documentController.delegate = self;

[documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];