0
我有一個應用程序需要能夠寫入/var/mobile/Applications/.../Documents目錄。這工作正常,但由於某種原因,現在當我運行我的代碼NSFileManager createFileAtPath每次都返回NO。我不知道爲什麼會發生這種情況,還有其他人嗎?我想知道如果我有點意外改變了一些目標設置...iPhone應用程序不再具有寫入權限
任何幫助表示讚賞,
羅賓
注:發生這種情況,因爲我嘗試寫入任何數據(的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);