我们如何在NSDefault在iOS 5中
问题描述:
复制的plist如何复制plist中在nsdefault iOS 5中我们如何在NSDefault在iOS 5中
这里是我的代码:
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPlistPath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat: @"%@.plist", @"Bookmark"] ];
// If it's not there, copy it from the bundle
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:myPlistPath]) {
NSString *pathToSettingsInBundle = [[NSBundle mainBundle]
pathForResource:@"Bookmark" ofType:@"plist"];
[fileManager copyItemAtPath:pathToSettingsInBundle toPath:myPlistPath error:&error];
}
[myPlistPath retain];
[myPlistPath release];
它运行在模拟器正确,但设备它崩溃。
答
首先,NSDefault也不是个事,只要甚至不使用NSUserDefaults
如果多数民众赞成你的意思,
现在行的代码:
[myPlistPath retain];
[myPlistPath release];
完全多余的,摆脱他们。
现在在调试时使用一些常识。
- cmd-shift-y调出控制台,看看它说什么。
- 检查该包是否存在
Bookmark.plist
,检查它是否存在于文档目录中。检查模拟器和设备。 - 执行崩溃在哪里?
- 设置一些日志例如
if (error) NSLog(@"Error:%@",error);
记录生成的路径。 - 确定
if (![fileManager fileExistsAtPath:myPlistPath])
评估为真或假。设置另一个日志。 - 剖析使用僵尸工具的运行。
下次再卡住时多做一点工作。
发布崩溃日志和堆栈。它会发生什么事? – zaph