【发布时间】:2011-06-09 18:02:37
【问题描述】:
我使用 NSKeyedArchiver 将我的 iPhone 应用程序中的数据归档为 .data。长话短说,我丢失了所有数据。我使用“iPhone 备份提取器”,效果很好。我为我的应用找到了一个 .data 文件。
为了清楚起见,我找到了一个 .data 文件,我想打开并查看其内容。我知道没有软件(例如:记事本)可能能够读取该文件,我可能不得不使用 Xcode。如果你知道任何方法,Xcode/notepad/someProgram,请告诉我。
这是我在构建应用程序时实现的代码:
- (NSString *)locPath {
return pathInDocumentDirectory(@"tableArray.data");
}
- (void)archieve{
// Get the path to the document directory
NSString *path = [self locPath];
// grab the array
NSMutableArray *tableArray = [someViewController tableArray];
// archive the array to file
[NSKeyedArchiver archiveRootObject:tableArray toFile:path];
}
此代码在 applicationWillTerminate、applicationDidEnterBackground 等期间调用...
在 didFinishLaunchingWithOptions 中恢复/调用数据,如下所示:
// Get the path to the document directory
NSString *path = [self locPath];
// Unarchive .data into an array
NSMutableArray *tableArray = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
感谢任何帮助!谢谢!!!
PS:iPhone备份提取器的链接是http://supercrazyawesome.com/
【问题讨论】: