gpt4 book ai didi

ios - NSKeyedArchiver 适用于模拟器但不适用于实际设备

转载 作者:行者123 更新时间:2023-11-29 10:40:19 30 4
gpt4 key购买 nike

所以我实现了这两个函数来在我的应用程序中保存数据:

- (NSString*)itemArchivePath
{
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentDirectory = [documentDirectories firstObject];

return [documentDirectory stringByAppendingString:@"items.archive"];
}


-(BOOL)saveChanges
{
NSString* path = [self itemArchivePath];
return [NSKeyedArchiver archiveRootObject:self.highScores toFile:path];
}

它在 iOS 模拟器上完美地保存了所有内容,但是当我在实际 iPhone 上运行它时,它没有保存任何内容。大多数应用程序都是用 swift 编写的,但我认为这不是问题所在。而且我确实实现了 NSCoding 的协议(protocol)。

最佳答案

您构建的路径不正确。

这个:

return [documentDirectory stringByAppendingString:@"items.archive"];

需要:

return [documentDirectory stringByAppendingPathComponent:@"items.archive"];

您的原始代码生成如下路径:

some path to app/Documentsitems.archive

请注意文件名前没有斜杠。

关于ios - NSKeyedArchiver 适用于模拟器但不适用于实际设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24846859/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com