Core data 如何将UIManagedDocument移动到iCloud

Core data 如何将UIManagedDocument移动到iCloud,core-data,icloud,uimanageddocument,nspersistentstore,Core Data,Icloud,Uimanageddocument,Nspersistentstore,将包含一些数据的UIManagedDocument从本地移动到iCloud目录的代码是什么? 我知道我需要使用migratePersistentStore功能,但当我不知道如何使用托管文档时,没有关于如何使用的示例。 我现在挣扎了两个星期。关于堆栈溢出有很多这样的问题,但没有一个得到答案?这难吗?只有一种方法可以将现有文档移动到iCloud -(void)transferFileFromLocalDirectory:(NSURL*)localURL ToiCloudDirectory:(NSUR

将包含一些数据的UIManagedDocument从本地移动到iCloud目录的代码是什么? 我知道我需要使用migratePersistentStore功能,但当我不知道如何使用托管文档时,没有关于如何使用的示例。 我现在挣扎了两个星期。关于堆栈溢出有很多这样的问题,但没有一个得到答案?这难吗?只有一种方法可以将现有文档移动到iCloud

-(void)transferFileFromLocalDirectory:(NSURL*)localURL ToiCloudDirectory:(NSURL*)iCloudURL{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSLog(@"Successfully set document ubiquitous");
            UIManagedDocument* doc=[[UIManagedDocument alloc]initWithFileURL:iCloudURL];
            doc.persistentStoreOptions=[self getPersistentOptionsFromDocumentMetadataAtURL:[iCloudURL URLByAppendingPathComponent:@"DocumentMetadata.plist"]];

            [doc saveToURL:doc.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success){
                UIManagedDocument* localDoc=[[UIManagedDocument alloc]initWithFileURL:localURL];
                NSPersistentStoreCoordinator* psc=[[NSPersistentStoreCoordinator alloc]initWithManagedObjectModel:localDoc.managedObjectModel];
                NSPersistentStore* store=[[psc persistentStores]lastObject];
                if(!store){
                    store=[[NSPersistentStore alloc]initWithPersistentStoreCoordinator:psc configurationName:nil URL:[[localURL URLByAppendingPathComponent:@"StoreContent"]URLByAppendingPathComponent:@"persistentStore"] options:nil];
                }
                NSLog(@"store : %@",store);
                NSError* error2=nil;
                [psc migratePersistentStore:store toURL:[[localURL URLByAppendingPathComponent:@"StoreContent"]URLByAppendingPathComponent:@"persistentStore"] options:nil withType:NSSQLiteStoreType error:&error2];
                if(error){
                    NSLog(@"error migrating persistent store:\n%@",error);
                }
            }];
    });
}
我得到这个输出

2013-12-07 20:15:45.284 iGymPRO[1111:3707] store : <NSPersistentStore: 0x15eb7a20> (URL: file:///var/mobile/Applications/610A9443-002A-42EA-8A66-E4D43F609672/Documents/Data%20Document/StoreContent/persistentStore)
2013-12-07 20:15:45.290 iGymPRO[1111:3707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't find store type for store <NSPersistentStore: 0x15eb7a20> (URL: file:///var/mobile/Applications/610A9443-002A-42EA-8A66-E4D43F609672/Documents/Data%20Document/StoreContent/persistentStore) (class == NSPersistentStore) in {
    Binary = "<8c3b9f3a>";
    InMemory = "<54419f3a>";
    SQLite = "<dc459f3a>";
}.'
2013-12-07 20:15:45.284 iGymPRO[1111:3707]商店:(URL:file:///var/mobile/Applications/610A9443-002A-42EA-8A66-E4D43F609672/Documents/Data%20Document/StoreContent/persistentStore)
2013-12-07 20:15:45.290 iGymPRO[1111:3707]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“找不到存储的存储类型(URL:file:///var/mobile/Applications/610A9443-002A-42EA-8A66-E4D43F609672/Documents/Data%20Document/StoreContent/persistentStore)(类==NSPersistentStore)位于{
二进制=”;
InMemory=“”;
SQLite=“”;
}.'
看看这个

同时也要看一看,确认一下你想要达到的目标