这似乎在模拟器中工作正常但在设备上没有写入文件。
这是代码。
-(void)saveOld{
NSArray *saveState = [NSArray arrayWithObjects:headArray,dropQArray,[NSNumber numberWithInt:dropLimit],[NSNumber numberWithInt:dropCount],[NSNumber numberWithInt:score],[NSNumber numberWithInt:level],[NSNumber numberWithInt:maxChain],nil];
NSMutableString *path = [[NSHomeDirectory() mutableCopy]autorelease];
[path appendString:@"/saveState"];
BOOL saved = [NSKeyedArchiver archiveRootObject:saveState toFile:path];
NSLog(@"did save state %d",saved);
path = [[NSHomeDirectory() mutableCopy]autorelease];
[path appendString:@"/isSaveState"];
saved = [NSKeyedArchiver archiveRootObject:[NSNumber numberWithBool:1] toFile:path];
NSLog(@"did save state %d",saved);
}
答案 0 :(得分:0)
iPhone上没有主目录:D
你应该改用:
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
这将为您提供基本文档目录,然后为其附加字符串。