我今天开始实现UIDocumentPickerViewController,但我遇到了困难。我让它导入文档并给出它的NSURL,但是当我使用iWork文档时,我使用的NSData是空的。这可能是因为iWork文档是目录而不是文件,我看了一下StackOverflow上的其他一些问题,除了压缩它们之外,似乎没有一个帮助或提供了解决方案,考虑到它们在各自的iWork应用程序中使用share sheet完成时,这似乎是错误的,它工作得很好。
下面是我的代码:
NSArray* components = [[url lastPathComponent] componentsSeparatedByString:@"."];
NSData* data = [[NSData alloc] initWithContentsOfURL:url];
NSString* filename = [[[url lastPathComponent] stringByReplacingOccurrencesOfString:[components lastObject] withString:@""] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString* newPath = [NSString stringWithFormat:@"%@/tmpFiles/%@%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0],filename,[components lastObject]];
[data writeToFile:newPath atomically:YES];
[self.files addObject:[NSURL fileURLWithPath:newPath]];
[self updateFileCount];其他人有没有想出解决这个问题的办法?谢谢。
发布于 2016-05-19 17:08:28
.pages或.numbers类型的文档不是单个文件,而是多个包。因此,您不能使用-dataWithContentsOfURL:来读取它们。
你用-copyItemAtURL:toURL:error:(NSFileManager)检查复制了吗?
https://stackoverflow.com/questions/32958348
复制相似问题