Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios iCloud&;核心数据-“;路径在任何CloudDocs容器之外,将永远不会同步;_Ios_Swift_Core Data_Icloud - Fatal编程技术网

Ios iCloud&;核心数据-“;路径在任何CloudDocs容器之外,将永远不会同步;

Ios iCloud&;核心数据-“;路径在任何CloudDocs容器之外,将永远不会同步;,ios,swift,core-data,icloud,Ios,Swift,Core Data,Icloud,所以我已经尝试使用核心数据和iCloud在两个iDevice之间同步数据几个星期了。苹果公司2012/2013年的报告是用Objective-C编写的,并不十分详细 我已尝试将其转换为iOS9的Swift 2.0。首先,我想我可能已经完成了,这是两个共享数据和同步任何更改的设备。然后事情变得一团糟,以前被删除的数据开始出现,唯一的同步方法就是重新启动应用程序。现在我遇到了这个错误: CoreData:Ubiquity:Library在启动时返回了一个严重错误 下载错误域=BRCloudDocsE

所以我已经尝试使用核心数据和iCloud在两个iDevice之间同步数据几个星期了。苹果公司2012/2013年的报告是用Objective-C编写的,并不十分详细

我已尝试将其转换为iOS9的Swift 2.0。首先,我想我可能已经完成了,这是两个共享数据和同步任何更改的设备。然后事情变得一团糟,以前被删除的数据开始出现,唯一的同步方法就是重新启动应用程序。现在我遇到了这个错误:

CoreData:Ubiquity:Library在启动时返回了一个严重错误 下载错误域=BRCloudDocsErrorDomain Code=6“路径在外部 任何CloudDocs容器的,将永远不会同步“

如果我继续通过Xcode(7)运行该应用程序,它似乎可以自行修复并同步更改,但这对现实世界并不理想;用户不必强制退出应用程序并重新启动以进行同步,如果数据已损坏,则重新安装

有没有人知道我哪里会出错,为什么会出错

完全错误:

2015-09-08 22:21:53.679 APPNAME[5550:407392] -  [PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](874): CoreData: Ubiquity:  nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B:APPNAMEStore
Using local storage: 1 for new NSFileManager current token <766b5e5c 3c205110 52c05248 38a47bd9 aca1ee87>
2015-09-08 22:21:57.639 APPNAME[5550:407392] storesDidChange posting notif
2015-09-08 22:21:57.639 APPNAME[5550:407452] -[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](874): CoreData: Ubiquity:  nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B:APPNAMEStore
 Using local storage: 0 for new NSFileManager current token <766b5e5c 3c205110 52c05248 38a47bd9 aca1ee87>
2015-09-08 22:21:58.565 APPNAME[5550:407476] __45-[PFUbiquityFilePresenter processPendingURLs]_block_invoke(447): CoreData: Ubiquity:  Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=6 "Path is outside of any CloudDocs container, will never sync" UserInfo={NSDescription=Path is outside of any CloudDocs container, will never sync, NSFilePath=/Users/USER/Library/Developer/CoreSimulator/Devices/19DE5FBA-9248-410D-9264-6B434B30F8CA/data/Containers/Data/Application/D00DA341-E9A5-4C65-82B4-41EFC5638ED3/Documents/CoreDataUbiquitySupport/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/DD2F75D5-FEAF-482A-A896-657936AFCFCD/container/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/NiGeopr_A~01pLnJTYkIei3RCNWt5FiSp0~iJS1V9eo=/38201B1B-7F78-4683-8604-D8F79D1F895B.1.cdt} with userInfo {
NSDescription = "Path is outside of any CloudDocs container, will never sync";
NSFilePath = "/Users/USER/Library/Developer/CoreSimulator/Devices/19DE5FBA-9248-410D-9264-6B434B30F8CA/data/Containers/Data/Application/D00DA341-E9A5-4C65-82B4-41EFC5638ED3/Documents/CoreDataUbiquitySupport/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/DD2F75D5-FEAF-482A-A896-657936AFCFCD/container/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/NiGeopr_A~01pLnJTYkIei3RCNWt5FiSp0~iJS1V9eo=/38201B1B-7F78-4683-8604-D8F79D1F895B.1.cdt";
} for these urls: {(
file:///Users/USER/Library/Developer/CoreSimulator/Devices/19DE5FBA-9248-410D-9264-6B434B30F8CA/data/Containers/Data/Application/D00DA341-E9A5-4C65-82B4-41EFC5638ED3/Documents/CoreDataUbiquitySupport/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/DD2F75D5-FEAF-482A-A896-657936AFCFCD/container/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/NiGeopr_A~01pLnJTYkIei3RCNWt5FiSp0~iJS1V9eo=/38201B1B-7F78-4683-8604-D8F79D1F895B.1.cdt
)}
2015-09-08 22:21:58.566 APPNAME[5550:407452] __45-[PFUbiquityFilePresenter processPendingURLs]_block_invoke(447): CoreData: Ubiquity:  Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=6 "Path is outside of any CloudDocs container, will never sync" UserInfo={NSDescription=Path is outside of any CloudDocs container, will never sync, NSFilePath=/Users/USER/Library/Developer/CoreSimulator/Devices/19DE5FBA-9248-410D-9264-6B434B30F8CA/data/Containers/Data/Application/D00DA341-E9A5-4C65-82B4-41EFC5638ED3/Documents/CoreDataUbiquitySupport/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/DD2F75D5-FEAF-482A-A896-657936AFCFCD/container/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/NiGeopr_A~01pLnJTYkIei3RCNWt5FiSp0~iJS1V9eo=/09F9706A-4479-47BF-B26D-DEBF92C55E48.1.cdt} with userInfo {
NSDescription = "Path is outside of any CloudDocs container, will never sync";
NSFilePath = "/Users/USER/Library/Developer/CoreSimulator/Devices/19DE5FBA-9248-410D-9264-6B434B30F8CA/data/Containers/Data/Application/D00DA341-E9A5-4C65-82B4-41EFC5638ED3/Documents/CoreDataUbiquitySupport/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/DD2F75D5-FEAF-482A-A896-657936AFCFCD/container/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/NiGeopr_A~01pLnJTYkIei3RCNWt5FiSp0~iJS1V9eo=/09F9706A-4479-47BF-B26D-DEBF92C55E48.1.cdt";
} for these urls: {(
file:///Users/USER/Library/Developer/CoreSimulator/Devices/19DE5FBA-9248-410D-9264-6B434B30F8CA/data/Containers/Data/Application/D00DA341-E9A5-4C65-82B4-41EFC5638ED3/Documents/CoreDataUbiquitySupport/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/DD2F75D5-FEAF-482A-A896-657936AFCFCD/container/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/NiGeopr_A~01pLnJTYkIei3RCNWt5FiSp0~iJS1V9eo=/09F9706A-4479-47BF-B26D-DEBF92C55E48.1.cdt,
file:///Users/USER/Library/Developer/CoreSimulator/Devices/19DE5FBA-9248-410D-9264-6B434B30F8CA/data/Containers/Data/Application/D00DA341-E9A5-4C65-82B4-41EFC5638ED3/Documents/CoreDataUbiquitySupport/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/DD2F75D5-FEAF-482A-A896-657936AFCFCD/container/nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B/APPNAMEStore/NiGeopr_A~01pLnJTYkIei3RCNWt5FiSp0~iJS1V9eo=/8DACD654-5C84-4699-B512-078D46E51947.1.cdt
)}
2015-09-08 22:22:02.865 APPNAME[5550:407497] mergeChanges notif:NSConcreteNotification 0x7fc53c926e80 {name = com.apple.coredata.ubiquity.importer.didfinishimport; object = <NSPersistentStoreCoordinator: 0x7fc53ae36700>; userInfo = {
deleted = "{(\n)}";
inserted = "{(\n)}";
updated = "{(\n)}";
}}

我以前也有过同样的问题。我花了半天时间检查代码,结果发现我使用了错误的iCloud容器名称。我在开发环境中有一个应用程序,它的名字和生产环境中的非常相似

我也看到了这个问题。
// MARK: - Core Data stack

// This handles the updates to the data via iCLoud updates
func registerCoordinatorForStoreNotifications (coordinator : NSPersistentStoreCoordinator) {
    let nc : NSNotificationCenter = NSNotificationCenter.defaultCenter();

    nc.addObserver(self, selector: "StoresWillChange:",
        name: NSPersistentStoreCoordinatorStoresWillChangeNotification,
        object: coordinator)

    nc.addObserver(self, selector: "StoresDidChange:",
        name: NSPersistentStoreCoordinatorStoresDidChangeNotification,
        object: coordinator)

    nc.addObserver(self, selector: "StoreChangedUbiquitousContent:",
        name: NSPersistentStoreDidImportUbiquitousContentChangesNotification,
        object: coordinator)
}


// Subscribe to NSPersistentStoreCoordinatorStoresWillChangeNotification
// most likely to be called if the user enables / disables iCloud
// (either globally, or just for your app) or if the user changes
// iCloud accounts.

func StoresWillChange (notification:NSNotification) {
    managedObjectContext.performBlock { () -> Void in
        if self.managedObjectContext.hasChanges {
            do {
                try self.managedObjectContext.save()
            } catch {
                print("error saving Managed Object Context in AppDelegate")
            }

            } else{
                // drop any manged object refrences
                self.managedObjectContext.reset()
            }

        }
    }

// Subscribe to NSPersistentStoreCoordinatorStoresDidChangeNotification
func StoresDidChange(notification: NSNotification) {
    // here is when you can refresh your UI and
    // load new data from the new store
    NSLog("storesDidChange posting notif");
    NSNotificationCenter.defaultCenter().postNotificationName("storeDidChange", object: nil)
}

func mergeChanges(notification: NSNotification) {
    NSLog("mergeChanges notif:\(notification)")
        self.managedObjectContext.performBlock {
            self.managedObjectContext.mergeChangesFromContextDidSaveNotification(notification)
        }
}

func StoreChangedUbiquitousContent(notification: NSNotification) {
    self.mergeChanges(notification);
}


lazy var applicationDocumentsDirectory: NSURL = {
    // The directory the application uses to store the Core Data store file. This code uses a directory named "com.USER.swift2-iCloud" in the application's documents Application Support directory.
    let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
    return urls[urls.count-1]
    }()

lazy var managedObjectModel: NSManagedObjectModel = {

    let modelURL = NSBundle.mainBundle().URLForResource("APPNAME", withExtension: "momd")!
    return NSManagedObjectModel(contentsOfURL: modelURL)!

    }()

lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {

    // Create the coordinator and store
    var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
    let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("APPNAME.sqlite")
    var error: NSError? = nil
    var failureReason = "There was an error creating or loading the application's saved data."
    // iCloud store
    var storeOptions = [NSPersistentStoreUbiquitousContentNameKey : "APPNAMEStore",NSMigratePersistentStoresAutomaticallyOption: true,
        NSInferMappingModelAutomaticallyOption: true]

    do {
        try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: NSURL.fileURLWithPath(url.path!), options: storeOptions)
    } 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"
        dict[NSLocalizedFailureReasonErrorKey] = failureReason
        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()
    }

    self.registerCoordinatorForStoreNotifications (coordinator!)

    return coordinator
    }()