Android 如何在Apportable中使用CoreData?
我正在尝试apportable的完整版本,但CoreData有问题: 我在configuration.json上有正确的功能:Android 如何在Apportable中使用CoreData?,android,core-data,apportable,Android,Core Data,Apportable,我正在尝试apportable的完整版本,但CoreData有问题: 我在configuration.json上有正确的功能: "FEATURES": ["opengles2","landscape","prefer_external_storage","write_external_storage","write_settings"], 设置要存储数据库的storageURL: #ifdef ANDROID //tried many different locations but not
"FEATURES": ["opengles2","landscape","prefer_external_storage","write_external_storage","write_settings"],
#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
现在问题出现在另一个地方:
// 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.momod”放入合适的项目中吗
谢谢很抱歉这么晚才回复,但我不想让这个问题无人回答。目前,momd文件不会自动添加为资产。不幸的是,每次更新xcdatamodeld时都需要手动执行一个步骤
~/Library/Application\Support/iPhone\simulator/6.1/Applications/.app/
)plutil-convert xml1.mom-o/.mom
add_params
字典中的configuration.json中,然后在assets
数组中,添加使用plutil转换的文件的路径/.mom
请注意,Starter SDK中不支持CoreData。如果您至少有Starter SDK,那么最好的选择可能是将演示该问题的完整项目发送给sdk@apportable.com. 对于Android和iOS,storeURL的指定应该不需要有什么不同。谢谢Paul,但我正在测试Apportable的完整版本。也许我试着把项目发送给sdk@apportable.com. 谢谢。在addPersistentStoreWithType:之后,我遇到了相同的崩溃。还使用Apportable的完整版本。我发现了导致崩溃的错误之一。我没有初始化NSError*error=nil;(编辑以更新错误)问题是否已解决。如果是的话,你可以分享解决方案。我也有类似的问题如果我有不同的数据库模型版本怎么办?Apportable现在支持二进制.mom文件,因此不再需要转换为xml的步骤。@Paul我在使用CoreData时设置正确的参数有困难。我已经在合适的论坛上发了帖子,在这里我认为这是我现在唯一的问题。
// 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;
}