Xcode中 - “提供的无处不在的名称已在使用” - 如何找到一个文件夹(Xcode - “Th

2019-10-17 11:40发布

我得到在Xcode中这条消息:

    The provided ubiquity name is already in use., 
NSURL=file://localhost/var/mobile/Applications/6C748748-9689-4F40-B8D7-
CDE8CA280FF8/Documents/SharedCoreDataStores/138F8194-DCC7-4D66-859B-
B2C35BDF2984/iCloudStore.sqlite

如何找到这个文件(iCloudStore.sqlite)的位置? 我试过〜/库/容器和〜/资源库/移动文件。

谢谢

Answer 1:

你可以找到它

NSURL *DocumentsURL = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject;

NSURL *tempURL = DocumentsURL;
tempURL = [tempURL URLByAppendingPathComponent:@"sharedCoreDataStores"];
tempURL = [tempURL URLByAppendingPathComponent:@"138F8194-DCC7-4D66-859B-B2C35BDF2984"];
tempURL = [tempURL URLByAppendingPathComponent:@"iCloudStore.sqlite"];
NSURL *iCloudStoreURL = tempURL;

iCloudStoreURL是你想要的。 您从iCloud中的演示代码核心数据创建这家店。 对?

你通过这个店网址[coordinator addPersistentStore]功能。


有两个位置,并使用iCloud的核心数据时,你应该注意到一个名字:

1. 商店网址

icloud的店真正的文件,将其存储在本地文件夹中的所有数据。 每个设备都有一个存储文件。 它将从iCloud中自动传输数据。

当添加的iCloud存储,您通过这个店网址[coordinator addPersistentStore]功能。

然后存储文件将定位在那个URL。

它应该在本地文件夹中,就像在documentsDirectory子目录

for example: 
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject URLByAppendingComponent:@"iCloudStore"];

或其他目录。 我的选择是

[[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask].lastObject URLByAppendingComponent:@"iCloudStore"];

2. iCloud的CoreData内容URL

此URL是在iCloud中的容器(或代号为“无处不在的容器”)。 它仅用于记录为核心的数据内容的变化。

认为它在云中。 [NSFileManager URLForUbiquityContainer:nil]是云的位置。

iCloud CoreData Content URL被用于这种普遍存在容器上的所有的iCloud核心数据的数据库传送日志。 (在不同的应用程序也许在同一容器普及和所有存储日志在这个不同的核心数据的数据库contentURL 。)

当您设置添加的iCloud存储的选项,你将这个网址:

 NSDictionary *cloudOptions =
 @{  NSMigratePersistentStoresAutomaticallyOption:@(YES),
 NSInferMappingModelAutomaticallyOption      :@(YES),
 NSPersistentStoreUbiquitousContentNameKey   :self.iCloudCoreDataContentName,
 NSPersistentStoreUbiquitousContentURLKey    :self.iCloudCoreDataContentURL}

这个URL应该是icloud的容器的子目录,像[[NSFileManager URLForUbiquityContainer:nil] URLByAppendingComponent:@"CoreDataLogs"]

这个属性是在选项可选。 如果你忽略它,icloud的CoreData内容URL将是[NSFileManager URLForUbiquityContainer:nil]

3. iCloud的CoreData内容名称

指定一个核心数据数据库中的唯一名称。 它要求每一个的iCloud存储。 不同的iCloud存储应该有不同的名称。

当您设置添加的iCloud存储的选项,你将这个名字:

 NSDictionary *cloudOptions =
 @{  NSMigratePersistentStoresAutomaticallyOption:@(YES),
 NSInferMappingModelAutomaticallyOption      :@(YES),
 NSPersistentStoreUbiquitousContentNameKey   :self.iCloudCoreDataContentName,
 NSPersistentStoreUbiquitousContentURLKey    :self.iCloudCoreDataContentURL}


文章来源: Xcode - “The provided ubiquity name is already in use” - how do I find a folder
标签: xcode icloud