无法弄清楚为什么archiveRootObject无法写入文件

时间:2022-03-01 21:11:15

this seems to work fine in the simulator but on the device the files are not being written.

这似乎在模拟器中工作正常,但在设备上没有写入文件。

here's the code.

这是代码。

-(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);
}

1 个解决方案

#1


0  

There is no home directory on the iPhone :D

iPhone上没有主目录:D

You should use this instead:

你应该使用它:

NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

This will give you the basic documents directory, append strings to it then.

这将为您提供基本文档目录,然后为其附加字符串。

#1


0  

There is no home directory on the iPhone :D

iPhone上没有主目录:D

You should use this instead:

你应该使用它:

NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

This will give you the basic documents directory, append strings to it then.

这将为您提供基本文档目录,然后为其附加字符串。