gpt4 book ai didi

ios - UIDocumentPickerViewController - 所有文件变灰

转载 作者:可可西里 更新时间:2023-11-01 03:02:05 26 4
gpt4 key购买 nike

我正在 iOS 8 中测试新的 UIDocumentPickerViewController API。我只想在 iCloud 中打开一个文件,看看交互是如何工作的。

这是我从我的 UIViewController 运行的代码:

- (IBAction)openDocument:(id)sender {
[self showDocumentPickerInMode:UIDocumentPickerModeOpen];
}

- (void)showDocumentPickerInMode:(UIDocumentPickerMode)mode {
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeData] inMode:mode];

picker.delegate = self;

[self presentViewController:picker animated:YES completion:nil];
}

openDocument 绑定(bind)到 IB 中的一个按钮。当我点击它时,它会打开 iCloud 浏览器,但其中的每个文件夹都是灰色的(我创建了一些测试 Keynote、Numbers 和 Pages 文件)所以我无法访问这些文件:

Document Picker with files grayed out .

我检查了一些文档并做了以下(没有运气):

  • 在我的应用中启用了 iCloud(在“功能”部分,用于键值存储和 iCloud 文档)。
  • 在我的 Info.plist 中添加了 public.data 的 UTI,如下所示:

    <key>CFBundleDocumentTypes</key>

    CFBundleTypeIconFile 图标.png CFBundleType名称 我的数据 CFBundleTypeRole 查看器 LSItemContentTypes 公共(public)数据 LSTypeIsPackage NS文档类 文档 NSPersistentStoreTypeKey 二进制

  • 将值为 YESNSUbiquitousContainerIsDocumentScopePublic 键添加到我的 Info.plist。

知道哪里有问题或遗漏了什么吗?

最佳答案

**Swift 3+ Solution**  

将打开并提供对驱动器上所有项目的访问权限。

//open document picker controller

func openImportDocumentPicker() {
let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
self.present(documentPicker, animated: true, completion: { _ in })
}
/*
*
* Handle Incoming File
*
*/

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
if controller.documentPickerMode == .import {
let alertMessage: String = "Successfully imported \(url.absoluteURL)"
}
}
/*
*
* Cancelled
*
*/

func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("Cancelled")
}

关于ios - UIDocumentPickerViewController - 所有文件变灰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24497213/

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