【发布时间】:2014-04-01 17:42:01
【问题描述】:
-(void) saveJsonToFile {
//Original document from Resources folder
NSString* saveFilePath = [[NSBundle mainBundle]pathForResource:@"data" ofType:@"json"];
//NSLog(@"Saving...%@", saveFilePath);
NSData* jsonData = [NSKeyedArchiver archivedDataWithRootObject:myArray];
BOOL success = [jsonData writeToFile:saveFilePath atomically:YES];
NSLog(success ? @"Yes" : @"No");
}
在模拟器上,它会记录 Yes。部署到我的 iPhone 时,它记录不。任何人都知道这是为什么以及如何修复它?提前致谢。
【问题讨论】:
-
对此不是 100% 确定,但我认为您正在尝试写入您的包,而不是您的 Documents 或 Temp 目录。 iOS 禁止这样做,但可能只在实际设备上强制执行。
标签: ios objective-c