2014-10-06 86 views
1

蘋果拒絕我的應用程序與崩潰日誌,表明他們已經在iOS 8.0.2的iPhone 6上測試它。我使用相同的iPhone 6和8.0.2測試了我的應用程序,它的工作原理非常完美。我通過iTunesConnect與testflight一起嘗試了它,假設這與蘋果的測試完全相同 - 顯然不是!蘋果拒絕 - 無法重現崩潰

有沒有人有一個想法,我怎麼能解決這個問題(在與審查小組的接觸已經有,但他們無法幫助,因爲他們說他們沒有技術支持,只是測試的應用程序。

我的問題是(從我的角度來看反正怪):它崩潰時,它添加了持久性存儲:

 NSError *error = nil; 
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { 
    /* 
    Replace this implementation with code to handle the error appropriately. abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 

    Typical reasons for an error here include: 
    * The persistent store is not accessible; 
    * The schema for the persistent store is incompatible with current managed object model. 
    Check the error message to determine what the actual problem was. 


    If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory. 

    If you encounter schema incompatibility errors during development, you can reduce their frequency by: 
    * Simply deleting the existing store: 
    [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil] 

    * Performing automatic lightweight migration by passing the following dictionary as the options parameter: 
    @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} 

    Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details. 

    */ 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
} 

顯然,它崩潰,因爲我在那裏有abort()聲明還,但我不確定該怎麼做(即處理該問題 - 只需刪除並嘗試再次添加商店?)

由於它在我的iPhone上完美運行,我假設它不是源代碼中列出的問題之一(如目錄,模型等),我是對嗎? 我現在正苦苦掙扎幾天,任何幫助或想法都不勝感激!

+0

你改變了模型嗎?嘗試安裝舊版本,添加一些數據,然後更新應用程序,也許你有一些數據遷移的問題。 – jcesarmobile 2014-10-06 06:05:29

+0

檢查此鏈接:http://stackoverflow.com/questions/13806849/handling-errors-in-addpersistentstorewithtype – kabarga 2014-10-06 06:10:30

+0

感謝您的意見。我沒有改變模型,當我測試它時它工作正常 - 所以我認爲這不可能是原因。 – Red 2014-10-06 06:14:43

回答

2

發生這種情況的常見原因是當storeURL中已有文件並且它不符合您指定的模型時。

至於那這裏的解決方法是你可以做什麼 1)啓用輕量級遷移 2)刪除現有的文件,然後再試一次

NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, 
          NSInferMappingModelAutomaticallyOption: @YES 
          }; 
BOOL successOfAdding = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
                    configuration:nil 
                       URL:storeURL 
                      options:options 
                      error:&error] != nil; 
if (successOfAdding == NO) 
{ 
    // Check if the database is there. 
    // If it is there, it most likely means that model has changed significantly. 
    if ([[NSFileManager defaultManager] fileExistsAtPath:storeURL.path]) 
    { 
     // Delete the database 
     [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]; 
     // Trying to add a database to the coordinator again 
     successOfAdding = [_persistentStoreCoordinator addPersistentStoreWithType: NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error] != nil; 
     if (successOfAdding == NO) 
     { 
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
      abort(); 
     } 
    } 

而關於拒絕 - 你有你的應用程序的早期版本? 另外,你在哪裏試圖存儲你的數據庫?可能有沒有訪問該路徑?

+0

感謝您的評論。它是應用程序的第一個版本,所以沒有以前版本的數據庫。我將數據庫存儲在'[[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];'問題是,它適用於我,但不知何故不適用於蘋果審查團隊 – Red 2014-10-06 10:20:52

+0

另一個問題是,如果 - 無論出於何種原因 - 用戶已經更新了數據庫,然後出現持久存儲的問題,我將刪除他的所有數據。 – Red 2014-10-06 10:48:22

+0

原因可能是:除非您有一些用戶生成的數據,否則它將被禁止在Documents目錄中存儲數據庫,因爲Documents目錄的內容可以在設備之間同步。這是不可能的,但在審查訪問文檔可能被阻止 – hybridcattt 2014-10-06 11:06:04