【问题标题】:how to move UIManagedDocument to iCloud如何将 UIManagedDocument 移动到 iCloud
【发布时间】:2013-12-24 23:59:53
【问题描述】:

将包含一些数据的 UIManagedDocument 从本地移动到 iCloud 目录的代码是什么? 我知道我需要使用 migratePersistentStore 功能,但是当我不明白如何使用托管文档执行此操作时,并且没有示例说明如何执行此操作。 我现在挣扎了2周。堆栈溢出有很多这样的问题,但没有一个得到答案?这很难吗?只有一种方法可以将现有文档移动到 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>";
}.'

【问题讨论】:

    标签: core-data icloud uimanageddocument nspersistentstore


    【解决方案1】:
    猜你喜欢
    • 2013-12-21
    • 2012-04-10
    • 2016-09-18
    • 1970-01-01
    • 2012-05-25
    • 2013-12-30
    • 2014-10-07
    • 2013-03-04
    • 1970-01-01
    相关资源
    最近更新 更多