如何Apportable使用的coredata? [英] How to use CoreData in Apportable?
问题描述
我想的完全版本apportable和我与的coredata一个问题:
我有正确的功能在configuration.json:
特征:opengles2,风景,prefer_external_storage,WRITE_EXTERNAL_STORAGE,write_settings],
-
设置storageURL,我想存储数据库:
的#ifdef ANDROID //尝试了许多不同的地方,但不是运气,我觉得有问题 NSURL * storeURL = [NSURL URLWithString:@/数据/数据/ com.bluepiggames.zombieSlice /文件/文件/ ZS_SuperDatabase.db]; #其他 NSURL * storeURL = [[自我applicationDocumentsDirectory] URLByAppendingPathComponent:@ZS_SuperDatabase]; #ENDIF
-
创建persistenceCoordinatore:
的NSDictionary *选项= [的NSDictionary dictionaryWithObjectsAndKeys: [NSNumber的numberWithBool:YES] NSMigratePersistentStoresAutomaticallyOption, [NSNumber的numberWithBool:YES] NSInferMappingModelAutomaticallyOption,零] _persistentStoreCoordinator = [[NSPersistentStoreCoordinator页头] initWithManagedObjectModel:自managedObjectModel];
-
最后,这些是地方的应用程序崩溃:
如果([_ persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType配置:无网址:storeURL选项:选择错误:放大器;错误]!){ 的NSLog(@未解决错误%@%@,错误,[错误USERINFO]); //中止();
和在调试器中没有任何错误提示,只有这样的崩溃。
F /的libc(10177):在0xe1a0d013致命的信号11(SIGSEGV)(code = 1) D / dalvikvm(7227):GC_CONCURRENT释放387K,12%的自由6566K / 7431K,暂停2MS + 2ms的 D / IabHelper(10177):查询SKU的详细信息。 I / DEBUG(8708):*** *** *** *** *** *** *** *** *** *** *** *** *** *** * ** *** I / DEBUG(8708):建立指纹:SoftWinnner / crane_a1002jhenergy /起重机a1002jhenergy:4.0.4 / IMM76D / 20120822:ENG /测试键 I / DEBUG(8708):PID:10177,TID:10218>>> com.bluepiggames.zombieSlice<<< I / DEBUG(8708):11(SIGSEGV),code 1(SEGV_MAPERR),故障地址e1a0d013 I / DEBUG(8708):R0 63c40b68 R1 6412b13c R2 6412b13c R3 00000000
(编辑)来解决这个崩溃,我们必须设置之前:
NSError *误差=零。 // !!!!!
如果([_ persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType配置:无网址:storeURL选项:选择错误:放大器;错误]!)
现在的问题是,在不同的地方:
//返回应用程序的管理对象模型。
//如果模型不存在,它是从应用程序的模型创建。
- (NSManagedObjectModel *)managedObjectModel
{
如果(_managedObjectModel!=无){
返回_managedObjectModel;
}
NSURL * modelURL = [[一个NSBundle mainBundle] URLForResource:@ZSDataModelwithExtension:@momd];
的NSLog(@测试managedModel发现%@,modelURL);
_managedObjectModel = [[NSManagedObjectModel页头] initWithContentsOfURL:modelURL]。
返回_managedObjectModel;
}
和错误是因为数据模型编译时发现。任何人都知道如何把编译后的DataModelDataModel.momod一个apportable项目中?
感谢
抱歉这么晚回应,但我不想让这个问题置之不理。现在momd文件不会被自动添加为资产。遗憾的是,你需要做的每次更新xcdatamodeld时间手动步骤。
- 在浏览到您的模拟器的应用程序目录(比如
〜/库/应用程序的\ Support / iPhone \模拟器/ 6.1 /应用/< randomString> /< YourApp>的.app /
) - 导航到momd目录
- 运行在终端如下:
plutil -convert xml1< MODELNAME> .mom -o< pathNearYourApprojFolder> /< MODELNAME> .mom
- 在
add_params
词典你configuration.json,然后在资产
阵列,添加路径< pathRelativeToApprojFolder> /< MODELNAME> .mom
您转换与plutil 李文件>
I trying the full version of apportable and I have a problem with the CoreData:
I have the correct features at configuration.json:
"FEATURES": ["opengles2","landscape","prefer_external_storage","write_external_storage","write_settings"],
Setting the storageURL where I want to store the DB:
#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
Creating the persistenceCoordinatore:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
Finally, these is the place where the app crash:
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); //abort();
And no error prompt in the debugger, only a crash like these.
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
(EDIT) To solve this crash we must set the before:
NSError *error = nil. //!!!!!
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
Now the problem is in a different place:
// 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;
}
And the error is because the DataModel compiled not found. Anybody knows how to put the compiled DataModel "DataModel.momod" inside a apportable project?
Thanks
sorry for such a late response, but i didn't want to let the question go unanswered. right now momd files aren't automatically added as assets. unfortunately, there's a manual step you'll need to do every time you update the xcdatamodeld.
- navigate to your simulator's Applications directory (e.g.
~/Library/Application\ Support/iPhone\ Simulator/6.1/Applications/<randomString>/<YourApp>.app/
) - navigate into the momd directory
- run the following in terminal:
plutil -convert xml1 <ModelName>.mom -o <pathNearYourApprojFolder>/<ModelName>.mom
- in your configuration.json in the
add_params
dictionary, then in theassets
array, add the path<pathRelativeToApprojFolder>/<ModelName>.mom
of the file you converted with plutil
这篇关于如何Apportable使用的coredata?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!