[英]How can I remove iCloud sync from core data database
我有一個應用程序,該應用程序正在使用舊的iCloud同步,並且我想刪除此功能。 因此,當我嘗試從persistentStoreCoordinator中的選項中刪除“ NSPersistentStoreUbiquitousContentNameKey”時,我將丟失整個數據庫項。 有人知道我該怎么做嗎? 遷移數據庫?
let containerPath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.de.companyName.appname")?.path
let sqlitePath = NSString(format: "%@/%@", containerPath!, "AppName")
let url = URL(fileURLWithPath: sqlitePath as String)
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
var error: NSError? = nil
var failureReason = "There was an error creating or loading the application's saved data."
let mOptions = [NSPersistentStoreUbiquitousContentNameKey: "AppNameCloud", NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true] as [String : Any]
do {
try coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: mOptions)
} catch var error1 as NSError {
error = error1
coordinator = nil
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data" as AnyObject?
dict[NSLocalizedFailureReasonErrorKey] = failureReason as AnyObject?
dict[NSUnderlyingErrorKey] = error
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// Replace this 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.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
} catch {
fatalError()
}
return coordinator
遷移是我要做的。 刪除無處不在的內容密鑰會使Core Data加載不同的持久性存儲。 由於它是新的並且是空的,因此您現有的數據不存在。
什么你做的是加載現有的iCloud數據存儲,然后使用migratePersistentStore(_:to:options:withType:)
對方法NSPersistentStoreCoordinator
到所有的數據移動到非的iCloud存儲。 完成后,開始使用新的存儲文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.