gpt4 book ai didi

iOS 自定义 UTI/文件类型与 UIDocumentPickerViewController

转载 作者:行者123 更新时间:2023-12-01 23:21:36 27 4
gpt4 key购买 nike

我有一个自定义文件类型,我试图允许我的应用程序从 UIDocumentPickerViewController 打开。然而,它并没有起作用。 (here 似乎描述了类似的情况和问题,但没有可行的解决方案。)

在我的 Info.plist 中我有:

<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>myext</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>document.icns</string>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>My document</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.mycompany.app.document</string>
</array>
<key>NSPersistentStoreTypeKey</key>
<string>Binary</string>
</dict>
</array>

和:

<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array/>
<key>UTTypeDescription</key>
<string>My document</string>
<key>UTTypeIdentifier</key>
<string>com.mycompany.app.document</string>
<key>UTTypeSize320IconFile</key>
<string>document</string>
<key>UTTypeSize64IconFile</key>
<string>document</string>
<key>public.filename-extension</key>
<array>
<string>myext</string>
<string>MYEXT</string>
</array>
</dict>
</array>

我正在实例化事物:

let picker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document"],
in: UIDocumentPickerMode.import)
picker.delegate = self
picker.modalPresentationStyle = UIModalPresentationStyle.fullScreen
self.present(picker, animated: true, completion: nil)

问题是,我的 iCloud 帐户中的“测试文件 I.myext”看起来像这样:

即灰显、不可选择、无法识别的文件。

我希望我做了一些明显错误的事情,但我看不到它。

最佳答案

你必须输入这样的内容:

<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>My Extension</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>myext</string>
</array>
</dict>
</array>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>myext file</string>
<key>LSItemContentTypes</key>
<array>
<string>com.mycompany.app.document.myext</string>
</array>
</dict>
</array>

<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>My Extension File</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>com.mycompany.app.document.myext</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myext</string>
</array>
</dict>
</dict>
<dict/>
</array>

此外,您还必须在 Controller 中添加如下内容:

let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document.myext"], in: .import)

应该有效

关于iOS 自定义 UTI/文件类型与 UIDocumentPickerViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49375657/

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