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 フォルダには何も表示されません。すべてが正常に見え、エラーも発生していないのに、アプリのフォルダが表示されないのはなぜでしょうか?
ベストアンサー1
同じコードを Swift で試してみましたが、同じ問題が発生しました。
私にとってはこれが効果的でした:
1) info.plistソースコードで次の行を見つけます
<key>CFBundleVersion</key>
<string>1</string>
2) バージョン番号を増やします。バージョン番号が 1 の場合は 2 に増やします。バージョン番号が何であっても同じ操作を行います。
3) 必要に応じて、デバイスからアプリをアンインストールし、上記の2つの手順を実行した後、再度実行してください。