我正在尝试检查/var/mobile/Documents/中是否存在文件,并且它在非 arm64 设备上完美运行。但是当我在arm64设备上尝试它时,它给了我cocoa错误257。
我在 ipad3/4 和 ipod5 上尝试过,效果很好。但是当我在 ipad mini 2 和 iPhone5S 上尝试时,它们都给了我 cocoa 错误 257。
我快速检查了一下文件是否可读,在 ipad3/4 和 ipod5 上得到"is",但在 ipad mini 2 和 5S 上得到“否”。
if ([[NSFileManager defaultManager] isReadableFileAtPath:@"/var/mobile/Documents/"] == YES) {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"yes" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[al show];
} else {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"no" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[al show];
}
如有任何帮助,我们将不胜感激!
最佳答案
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = paths[0];
if([[NSFileManager defaultManager] isReadableFileAtPath:documentsDirectoryPath]) {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"yes"
message:nil
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[al show];
}
else {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"no"
message:nil
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[al show];
}
关于objective-c - NSFileManager 找不到/var/mobile/的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22735005/