mol*_*ira 2 ios icloud nspersistentstore
我一直在努力将iCloud存储迁移到应用程序沙箱中的本地存储.代码如下所示(为清楚起见,错误处理代码已被删除):
NSPersistentStore *iCloudStore = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:legacyStoreUrl options:options error:&error];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *targetStoreUrl = [self localStorageUrl];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
[_persistentStoreCoordinator migratePersistentStore:legacyStore toURL:targetStoreUrl options:options withType:NSSQLiteStoreType error:nil];
Run Code Online (Sandbox Code Playgroud)
此时我们已成功将iCloud存储迁移到应用程序沙箱中的新位置,但iCloud和旧的sqlite文件中仍有数据...以下行删除了sqlite文件
[fileManager removeItemAtURL:legacyStoreUrl error:nil]
Run Code Online (Sandbox Code Playgroud)
因此,在运行所有这些后,我的文件系统和持久性商店看起来很好,据我所知.缺少的一点是存储在iCloud中的数据不会从iCloud中删除(尽管应用程序不再访问它).以编程方式删除iCloud数据还需要做些什么?苹果iCloud文档提到删除事务日志但我没有看到我的Documents文件夹中需要清理的任何其他文件.任何帮助深表感谢!
更新:
最初使用以下选项设置iCloud存储:
NSURL *ubiquityContainerUrl = [fileManager URLForUbiquityContainerIdentifier:nil];
NSString* coreDataCloudContent = [[ubiquityContainerUrl path] stringByAppendingPathComponent:@"data"];
NSURL *coreDataUrl = [NSURL fileURLWithPath:coreDataCloudContent];
options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
@"MyAppName.store", NSPersistentStoreUbiquitousContentNameKey,
coreDataUrl, NSPersistentStoreUbiquitousContentURLKey,
nil];
Run Code Online (Sandbox Code Playgroud)
我刚刚发现Xcode允许您使用Xcode菜单重置容器:
Debug->iCloud->Delete Container Contents
Run Code Online (Sandbox Code Playgroud)
能够在线查看内容也很有帮助:https://developer.icloud.com/
| 归档时间: |
|
| 查看次数: |
6063 次 |
| 最近记录: |