[英]Why my app is not shown in iCloud Drive Folder
iCloud Drive 文件夾不顯示我的應用程序的文件夾。
這是我將文件發送到 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];
}
實際上我做了這篇文章中解釋的一切
一切看起來都很好。 我可以成功上傳文件,我可以通過終端在我的電腦上顯示它們。
我可以看到我剛剛從我的 iphone 上傳的文件。
但是我的 mac 或 icloud.com 中的 iCloud Drive 文件夾中沒有顯示任何內容。 為什么他們不顯示我的應用程序的文件夾,即使一切看起來都很好並且沒有錯誤?
我在 swift 中嘗試了相同的代碼並遇到了同樣的問題。
這對我有用:
1) 在 info.plist 源代碼中找到以下幾行
<key>CFBundleVersion</key>
<string>1</string>
2)增加版本號。 如果是 1,就增加到 2。不管版本號是多少,都一樣。
3) 如果需要,請從您的設備上卸載該應用程序,然后按照上述兩個步驟重新運行它
在現有應用程序中唯一對我URLForUbiquityContainerIdentifier
(我遇到了完全相同的問題)(因此我無法更改包 ID)是在URLForUbiquityContainerIdentifier
文件夾下創建一個Documents
子文件夾並將我的所有文件寫入那里。
一旦我這樣做了,它們就會出現在我的 Mac 上的 Finder 中。 但是,它們沒有出現在 iCloud Drive 中我的應用程序Documents
夾的Documents
子文件夾中,它們直接出現在應用程序文件夾中。
但是我的 mac 或 icloud.com 的 iCloud Drive 文件夾中沒有顯示任何內容。 為什么他們不顯示我的應用程序文件夾,即使一切看起來都很好並且沒有錯誤?
這是一個新的應用程序還是一個新創建的 iCloud 容器? 那么原因是: NSUbiquitousContainerIsDocumentScopePublic=true 僅在應用程序(和授權的 iCloud 容器)通過審查和批准后才生效。
我不記得我在哪里讀到“丟失的信息”(至少我沒有從 Apple 文檔中得到它)。
我的經驗中的另一個例子似乎證明了這一點:在現有應用程序(使用“舊樣式 - TeamIdentifierPrefix”iCloud 容器)中,我可以使該容器在 iCloud 驅動器上可見。 但是一個新的容器不會在 iCloud Drive 中“對公眾”可見(即使我在 Mac 上使用 Terminal.app 也能看到它)。 一旦應用程序(帶有新容器)被批准並在 AppStore 上可用,您可以再次使用 Info.plist 播放(並使新容器可見/隱藏,...)
我的情況是我錯過了你在Info.plist
的容器應該被包裝到NSUbiquitousContainers
字典。
我已修復並增加build version
,該文件夾確實出現了。
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com....</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>The name at iCloud folder</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.