我尝试了完整版本的可移植性,但 CoreData 有问题:
我在configuration.json中有正确的功能:
"FEATURES": ["opengles2","landscape","prefer_external_storage","write_external_storage","write_settings"],
-
设置我想要存储数据库的 storageURL:
#ifdef ANDROID
//tried many different locations but not luck, I think there is the problem
NSURL *storeURL = [NSURL URLWithString:@"/data/data/com.bluepiggames.zombieSlice/files/Documents/ZS_SuperDatabase.db"];
#else
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ZS_SuperDatabase"];
#endif
-
创建持久性协调器:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES],
NSInferMappingModelAutomaticallyOption, nil];
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel: [self managedObjectModel]];
-
最后,这些是应用程序崩溃的地方:
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
//abort();
并且调试器中没有错误提示,只有这样的崩溃。
F/libc (10177): Fatal signal 11 (SIGSEGV) at 0xe1a0d013 (code=1)
D/dalvikvm( 7227): GC_CONCURRENT freed 387K, 12% free 6566K/7431K, paused 2ms+2ms
D/IabHelper(10177): Querying SKU details.
I/DEBUG ( 8708): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 8708): Build fingerprint: 'SoftWinnner/crane_a1002jhenergy/crane-a1002jhenergy:4.0.4/IMM76D/20120822:eng/test-keys'
I/DEBUG ( 8708): pid: 10177, tid: 10218 >>> com.bluepiggames.zombieSlice <<<
I/DEBUG ( 8708): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr e1a0d013
I/DEBUG ( 8708): r0 63c40b68 r1 6412b13c r2 6412b13c r3 00000000
(编辑)要解决此崩溃,我们必须设置之前:
NSError *error = nil. //!!!!!
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
现在问题出在不同的地方:
// Returns the managed object model for the application.
// If the model doesn't already exist, it is created from the application's model.
- (NSManagedObjectModel *)managedObjectModel
{
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"ZSDataModel" withExtension:@"momd"];
NSLog(@"Test managedModel found %@",modelURL);
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
错误是因为找不到编译的DataModel。有人知道如何将编译后的数据模型“DataModel.momod”放入可移植的项目中吗?
Thanks
很抱歉这么晚才回复,但我不想让这个问题得不到解答。现在,mod 文件不会自动添加为资产。不幸的是,每次更新 xcdatamodeld 时都需要执行手动步骤。
- 导航到模拟器的应用程序目录(例如
~/Library/Application\ Support/iPhone\ Simulator/6.1/Applications/<randomString>/<YourApp>.app/
)
- 导航到 momd 目录
- 在终端中运行以下命令:
plutil -convert xml1 <ModelName>.mom -o <pathNearYourApprojFolder>/<ModelName>.mom
- 在你的configuration.json中
add_params
字典中,然后在assets
数组,添加路径<pathRelativeToApprojFolder>/<ModelName>.mom
使用 plutil 转换的文件的
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)