gpt4 book ai didi

ios - 为什么我的应用程序没有显示在 iCloud Drive 文件夹中

转载 作者:技术小花猫 更新时间:2023-10-29 10:16:25 39 4
gpt4 key购买 nike

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];
}

实际上我做了所有解释in this post

一切看起来都很好。我可以成功上传文件,我可以通过终端在我的电脑上显示它们。

enter image description here

enter image description here

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

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

最佳答案

我在 swift 中尝试了相同的代码并遇到了同样的问题。

这对我有用:

1) 在您的 info.plist 源代码中找到以下几行

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

2) 增加版本号。如果是 1,则将其增加到 2。无论版本号是多少,都执行相同的操作。

3) 如果需要,请从您的设备上卸载该应用程序,并在执行上述两个步骤后重新运行

关于ios - 为什么我的应用程序没有显示在 iCloud Drive 文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30385940/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com