为什么我的应用程序未显示在iCloud Drive文件夹中

iCloud驱动器文件夹不显示我的应用程序的文件夹。

这是我如何发送文件到iCloud Drive:

- (IBAction)btnStoreTapped:(id)sender { // Let's get the root directory for storing the file on iCloud Drive [self rootDirectoryForICloud:^(NSURL *ubiquityURL) { NSLog(@"1. ubiquityURL = %@", ubiquityURL); if (ubiquityURL) { // We also need the 'local' URL to the file we want to store //NSURL *localURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Photo" ofType:@"pdf"]]; NSURL *localURL = [self localPathForResource:@"document" ofType:@"doc"]; NSLog(@"2. localURL = %@", localURL); // Now, append the local filename to the ubiquityURL ubiquityURL = [ubiquityURL URLByAppendingPathComponent:localURL.lastPathComponent]; NSLog(@"3. ubiquityURL = %@", ubiquityURL); // And finish up the 'store' action NSError *error; if (![[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:localURL destinationURL:ubiquityURL error:&error]) { NSLog(@"Error occurred: %@", error); }else{ NSLog(@"Succeed"); } } else { NSLog(@"Could not retrieve a ubiquityURL"); } }]; } - (void)rootDirectoryForICloud:(void (^)(NSURL *))completionHandler { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSURL *rootDirectory = [[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:@"Documents"]; if (rootDirectory) { if (![[NSFileManager defaultManager] fileExistsAtPath:rootDirectory.path isDirectory:nil]) { NSLog(@"Create directory"); [[NSFileManager defaultManager] createDirectoryAtURL:rootDirectory withIntermediateDirectories:YES attributes:nil error:nil]; } } dispatch_async(dispatch_get_main_queue(), ^{ completionHandler(rootDirectory); }); }); } - (NSURL *)localPathForResource:(NSString *)resource ofType:(NSString *)type { NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString *resourcePath = [[documentsDirectory stringByAppendingPathComponent:resource] stringByAppendingPathExtension:type]; return [NSURL fileURLWithPath:resourcePath]; } 

其实我已经在这篇文章中解释过了

一切看起来都很好。 我可以成功上传文件,并可以通过terminal在电脑上显示。

在这里输入图像说明

在这里输入图像说明

我可以看到我刚从iPhone上传的文件。

但没有任何显示在我的Mac或icloud.com的iCloud Drive文件夹中。 为什么他们没有显示我的应用程序的文件夹,即使一切看起来很好,没有错误?

在现有的应用程序(所以我不能更改包ID)唯一的工作对我来说(我有完全相同的问题)是在URLForUbiquityContainerIdentifier文件夹下创build一个Documents子文件夹,并写在那里我所有的文件。

一旦我做到了,他们就出现在我的Mac上的Finder中。 但是,他们没有出现在我的应用程序在iCloud Drive中的Documents夹的Documents子文件夹,他们直接出现在应用程序文件夹。

但没有任何显示在我的Mac或icloud.com的iCloud Drive文件夹中。 为什么他们没有显示我的应用程序的文件夹,即使一切看起来很好,没有错误?

这是一个新的应用程序或新创build的iCloud容器? 那么原因是:NSUbiquitousContainerIsDocumentScopePublic = true只有在应用程序(以及有权利的iCloud容器)通过审核后才会生效。

我不记得我在哪里读到“缺less的信息”(至less我没有从苹果文档中得到它)。

另一个来自我的经验的例子,这似乎certificate了这一点:在现有的应用程序(“老式 – TeamIdentifierPrefix”iCloud容器)我可以使该容器可见的iCloud驱动器。 但是一个新的容器在iCloud Drive“向公众”中是不可见的(即使我可以在我的Mac上使用Terminal.app来查看它)。 一旦应用程序(与新的容器)已被批准,并在AppStore上可用,您可以再次玩Info.plist(并使新的容器可见/隐藏,…)

我已经尝试了相同的代码,并得到了同样的问题。

这对我来说是有效的:

1)在你的info.plist源代码中find以下几行

 <key>CFBundleVersion</key> <string>1</string> 

2)增加版本号。 如果是1,则将其增加到2.无论版本号是多less,都要一样。

3)如果需要,从您的设备上卸载应用程序,并按照上述两个步骤重新运行它

  1. 在Info.plist中打击CFBundleVersion。
  2. https://developer.apple.com/account/ios/identifier/cloudContainer上创build一个新的iCound容&#x5668;
  3. 在Xcode中指定自定义容器。 取消旧容器并勾选新创build的容器。