简体   繁体   English

让 UIDocumentPickerViewController 只允许在 iOS 13 上选择二进制数据文件

[英]Getting UIDocumentPickerViewController to only allow the selection of binary data files on iOS 13

My app is stuck at iOS 13 for the time being, and I can't get the UIDocumentPickerViewController only to allow the selection of binary files.我的应用程序暂时停留在 iOS 13,我无法获取 UIDocumentPickerViewController 仅允许选择二进制文件。

This is what I'm putting into my info.plist这就是我要放入 info.plist 的内容

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeIdentifier</key>
        <string>public.firmware</string>
        <key>UTTypeDescription</key>
        <string>Firmware Binary</string>
        <key>UTTypeIconFile</key>
        <string></string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeIconFiles</key>
        <array/>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>bin</string>
            </array>
            <key>public.mime-type</key>
            <string>application/octet-stream</string>
        </dict>
    </dict>
</array>

Here's what I'm hooking up to a button upon selection这是我在选择时连接到按钮的内容

let vc = UIDocumentPickerViewController(documentTypes: ["public.firmware"], in: .import)
    vc.delegate = self
    
    self.present(vc, animated: true)

I'd use UTType but it's not available in iOS 13. Also, I'm not sure if I'm using the correct mime-type.我会使用 UTType,但它在 iOS 13 中不可用。另外,我不确定我是否使用了正确的 mime 类型。 I chose octet-stream from this list https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types我从这个列表中选择了八位字节流https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

What is your goal exactly?你的目标到底是什么? Allow selecting files with the file extension .bin?允许选择文件扩展名为 .bin 的文件吗?

The .bin tag is already claimed by com.apple.macbinary-archive, so to do that you should avoid redeclaring your own type and just use that Apple-provided type directly. com.apple.macbinary-archive 已经声明了 .bin 标记,因此您应该避免重新声明自己的类型,而直接使用 Apple 提供的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS 13 如何将UIDocumentPickerViewController 与App Group 一起使用? - iOS 13 How to use UIDocumentPickerViewController with App Group? UIDocumentPickerViewController的局限性,一次选择多个文件 - UIDocumentPickerViewController Limitations, Multiple Files selection at once iOS 13 仅在用户“允许一次”后再次调用 requestAlwaysAuthorization - iOS 13 call requestAlwaysAuthorization again after user “Allow Once” only 是否可以仅允许基于 iOS 13 上的视图 controller 的特定方向? - Is it possible to allow only specific orientations based on view controller on iOS 13? iOS13 UIDocumentPickerViewController - 打开目录不显示选择/打开/取消按钮 - iOS13 UIDocumentPickerViewController - open directory does not display select/open/cancel buttons iOS 14 中 UIDocumentPickerViewController 的初始化 - Initialization of UIDocumentPickerViewController in iOS 14 UIDocumentPickerViewController不显示所有文件 - UIDocumentPickerViewController not showing all files UIDocumentPickerViewController 文件被禁用? - UIDocumentPickerViewController files disabled? iOS 13 如何检查用户只给定始终允许位置权限 - iOS 13 How to check user is given only Always allow location permission iOS 13 中“始终允许”位置的问题 - Issues with “Allow always” location in iOS 13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM