访问“私人文档”中的文件使用 iTunes 传输的文件夹
目前,我正在尝试访问使用 3.2 引入的新 iOS 功能传输的文件。
- (NSString *)getPrivateDocsDir {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Private Documents"];
NSError *error;
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:&error];
return documentsDirectory;
}
// and then in a method
NSString *documentsDirectory = [self getPrivateDocsDir];
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
问题是,这在模拟器中工作正常,但在我的 iPhone 上,files
数组为空。
有什么想法如何直接访问该目录吗?
Currently I'm trying to access the files that are transferred using the new iOS feature introduced with 3.2.
- (NSString *)getPrivateDocsDir {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Private Documents"];
NSError *error;
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:&error];
return documentsDirectory;
}
// and then in a method
NSString *documentsDirectory = [self getPrivateDocsDir];
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
The problem is, this works fine in simulator, but on my iphone, the files
array is empty.
Any ideas how to access this directory directly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法通过 iTunes 访问 Library-Directory,并且“私人文档”位于该库目录内。
顾名思义,私人文件是私人的。故意不通过 iTunes 访问它们。
如果您想访问文档目录(可通过 itunes 访问),请将其替换
为:
编辑:
像这样访问文件。
The Library-Directory is not accessible through iTunes, and "Private Documents" is inside this library directory.
The private documents, are, as the name suggests, private. They are intentionally not accessible through iTunes.
If you want to access the documents directory (which is accessible through itunes) replace this
with this:
EDIT:
Access the files like this.