iPhone App不再具有写入权限

时间:2012-06-20 17:11:49

标签: iphone objective-c nsfilemanager

我有一个应用程序,需要能够写入/var/mobile/Applications/.../Documents目录。这工作正常,但由于某些原因,现在当我运行我的代码NSFileManager时,createFileAtPath每次都返回NO。我不知道为什么会这样,其他人呢?我想知道我是不是意外地改变了一些目标设置......

感谢任何帮助,

罗宾

注意:我尝试编写的任何数据(NSString,NSDictionary等)

都会出现这种情况
NSDictionary *dataToWrite = [[NSDictionary alloc] initWithObjectsAndKeys:@"1234", @"id", @"hfjk", @"password",nil]; 
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(

                                                          NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [arrayPaths objectAtIndex:0];
filePath = [docDirectory stringByAppendingString:@"/sample-file-name"];
NSFileManager *fileMgr;
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:dataToWrite forKey:@"any-key"];
[archiver finishEncoding];

BOOL status = [fileMgr createFileAtPath:path contents:data attributes:nil];
if (status)
    NSLog(@"Created file at path: %@",path);
else
    NSLog(@"Failed to create file at path: %@",path);

1 个答案:

答案 0 :(得分:0)

而不是写作,

filePath = [docDirectory stringByAppendingString:@"/sample-file-name"];

请查看

filePath = [docDirectory stringByAppendingPathComponent:@"sample-file-name"];

请检查NSFileManager Class Reference