iTunes 同步后数据丢失
我有一个应用程序,它将其用户数据保存到文档目录中的文件中,如下所示:
NSLog(@"Saving myLibrary.dat...");
NSString *filePath = [[self documentsDirectory] stringByAppendingPathComponent:@"myLibrary.dat"];
BOOL succeed = [[NSKeyedArchiver archivedDataWithRootObject:myLibrary] writeToFile:filePath atomically:YES];
if (!succeed){
NSLog(@"There was an error saving myLibrary.dat!");
}
和我的文档目录:
-(NSString*)documentsDirectory
{
NSLog(@"documentsDirectory");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory
return documentsDirectory;
}
库 dat 保存 myLibrary,它是一个 NSMutableArray,其中包含许多其他 NSMutableArray 或 NSString。
我从来没有遇到过应用程序保存数据的任何问题,但现在有用户报告说,在他进行 iTunes 同步后,他的资料库变得混乱(项目被重复或交换)。
我还没有使用 iTunes 同步设置任何同步功能,因此不知道为什么他会遇到这个错误?
任何人都可以想到其中的联系,还是只是这样的情况:该错误必须在其他地方(在我的应用程序中)找到,并且用户可能只是在 iTunes 同步后偶然遇到该错误?
任何想法将不胜感激!
I have an app which saves its user data into a file in the documents directory like so:
NSLog(@"Saving myLibrary.dat...");
NSString *filePath = [[self documentsDirectory] stringByAppendingPathComponent:@"myLibrary.dat"];
BOOL succeed = [[NSKeyedArchiver archivedDataWithRootObject:myLibrary] writeToFile:filePath atomically:YES];
if (!succeed){
NSLog(@"There was an error saving myLibrary.dat!");
}
and my documents directory:
-(NSString*)documentsDirectory
{
NSLog(@"documentsDirectory");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory
return documentsDirectory;
}
The library dat saves myLibrary which is an NSMutableArray with lots of other NSMutableArrays or NSStrings.
I have never experienced any problems with the app keeping my data save, but a user has now reported that his library gets messed up (items are being duplicated or swapped) after he does an iTunes sync.
I have not set up any syncing features with iTunes sync and have therefore no clue why he is experiencing this bug?
Can anyone think of a connection or is it simply the case that the bug must be found elsewhere (in my app) and that the user has perhaps only by chance experienced the bug right after an iTune sync?
Any thoughts would be very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试保存在 NSUserDefaults 而不是文件中。
Try to save in the NSUserDefaults instead of a file.