2015-11-19 100 views
0

我已將iCloud支持添加到我的核心數據。當我向數據庫添加內容時,關閉應用程序並嘗試再次打開該應用程序不啓動,它掛在我的啓動屏幕上,並在控制檯中看到兩個信息。首先,它會嘗試連接到位於.../CoreDataUbiquitySupport/...和第二SQLite數據庫文件是該iOS 9:使用iCloud的核心數據:掛上addPersistentStoreWithType

CoreData: sql: pragma journal_mode=delete 

我認爲它發生只在模擬器。

這是什麼意思?哪裏不對?

它掛在addPersistentStoreWithType功能,幾分鐘後功能與例外

Error adding persistent store to coordinator: Error Domain=NSCocoaErrorDomain Code=134090 "(null)" UserInfo={NSSQLiteErrorDomain=5, NSUnderlyingException=error during SQL execution : The database operation timed out after 240.00 seconds. 

這裏返回的是我怎麼添加持久性存儲:

let options = [ 
     NSInferMappingModelAutomaticallyOption: true, 
     NSMigratePersistentStoresAutomaticallyOption: true, 
     NSPersistentStoreUbiquitousContentNameKey: "AppCloudStore" 
    ] 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { 
     do { 
      self.store = try self.storeCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, 
       configuration: nil, 
       URL: storeURL, 
       options: options) 

      self.initialized = true 
     } catch let error as NSError { 
      print(error) 
     } 
    }) 

回答

0

問題似乎是用journal_mode。我刪除它或將模式更改爲WAL後,我不再有鎖定問題。 (這是在實際設備上使用iOS 9.1,而不是在商店中使用iCloud。)

如果您在掛起期間暫停程序(或掛起),您可以看到它正在訪問fcntl函數(或有時在sqlite3.dylib)而是輪詢/無限循環;在此期間,我的CPU處於100%CPU)。