2013-10-15 40 views
2

我试图完整版apportable和我与CoreData一个问题:如何在Apportable中使用CoreData?

我有正确的功能在configuration.json:

"FEATURES": ["opengles2","landscape","prefer_external_storage","write_external_storage","write_settings"], 
  1. 设置在这里我想存储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 
    
  2. 创建persistenceCoordinatore:

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: 
              [NSNumber numberWithBool:YES], 
              NSMigratePersistentStoresAutomaticallyOption, 
              [NSNumber numberWithBool:YES], 
              NSInferMappingModelAutomaticallyOption, nil]; 
    
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] 
           initWithManagedObjectModel: [self managedObjectModel]]; 
    
  3. 最后,这些是地方的应用程序崩溃:

    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 
    

(EDIT)为了解决这个崩溃,我们必须将前:

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“DataModel.momod”放入一个可配置的项目中?

感谢

+0

请注意,CoreData不支持在Starter SDK中。如果您至少有Starter SDK,最好的办法可能是将完整的项目发送到[email protected]。 storeURL应该不需要为iOS指定不同的iOS版本。 –

+0

感谢Paul,但我正在测试Apportable的完整版本。也许我会尝试将该项目发送到[email protected]。谢谢。 –

+0

我在addPersistentStoreWithType之后遇到同样的问题:还使用完整版的Apportable。 –

回答

2

抱歉这么晚回应,但我不想让这个问题置之不理。现在momd文件不会自动添加为资产。不幸的是,每次更新xcdatamodeld时都需要执行手动步骤。

  1. 浏览到您的模拟器的应用程序目录(例如~/Library/Application\ Support/iPhone\ Simulator/6.1/Applications/<randomString>/<YourApp>.app/
  2. 导航到momd目录
  3. 运行在终端如下:plutil -convert xml1 <ModelName>.mom -o <pathNearYourApprojFolder>/<ModelName>.mom
  4. 在configuration.json
  5. add_params字典,然后在assets数组,添加您使用plutil转换的文件的路径<pathRelativeToApprojFolder>/<ModelName>.mom
+0

如果我有不同型号的数据库,该怎么办? –

+1

Apportable现在支持二进制。妈妈文件,所以转换到XML的步骤不再需要。 –

+0

@Paul我在使用CoreData时无法设置正确的参数。我已经张贴在Apportable论坛,也在这里http://stackoverflow.com/questions/23754932/what-is-the-correct-way-of-using-the-xcdatamodels-parameters-in-the-apportable-c我认为这是我现在唯一的问题。 –