Re: Help with UTIs and UIDocumentPickerViewController


Alex Zavatone
 

Is this the section where you are specifying the file type?

<key>public.filename-extension</key>
<array>
     <string>msug</string>
</array>
</dict>

Does that look correct for a CSV file?

Alex Zavatone


On Feb 9, 2021, at 3:43 PM, Rick Aurbach via groups.io <rlaurb@...> wrote:

I am writing a small utility app that reads CSV files, processes the contents, and outputs the result in a different format.

I want to use UIDocumentPickerViewController to select the file to be processed. (Appropriate code is below.) I load test data into the Simulator by drag-and-drop from my Mac to the Simulator's Files app. When I present the picker, it shows the files I added, but they are all in a disabled state and cannot be selected.

I assume that this is due to a problem with the UTIs in my info.plist file, but I don't know what I'm doing wrong. Can anyone help me?

Code:

lazy var inputPicker: UIDocumentPickerViewController = {

let picker: UIDocumentPickerViewController

if #available(iOS 14, *) {

guard let uttype = UTType("public.comma-delimited-values-text") else { fatalError() }

picker = UIDocumentPickerViewController(forOpeningContentTypes: [uttype])

} else {

picker = UIDocumentPickerViewController(documentTypes: ["public.comma-delimited-values-text"], in: .import)

}

picker.delegate = self

picker.allowsMultipleSelection = false

return picker

}()


chooseFile.onTap { btn in

self.present(self.inputPicker, animated: true, completion: nil)

}



From the Info.plist file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Comma-Delimited Text File</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>public.comma-delimited-values-text</string>
</array>
</dict>
<dict>
<key>CFBundleTypeName</key>
<string>Morning Sugar Import File</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.aurbach.morning-sugar-data</string>
</array>
</dict>
</array>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.comma-delimited-values-text</string>
</array>
<key>UTTypeDescription</key>
<string>Morning Sugar Import File</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>com.aurbach.morning-sugar-data</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>msug</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.delimited-values-text</string>
</array>
<key>UTTypeDescription</key>
<string>Comma-Separated Values File </string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>public.comma-delimited-values-text</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>csv</string>
</array>
</dict>
</dict>
</array>

(note: Since this utility app does not originate the definition of either of these UTIs, I have specified UIImportedTypesDeclarations, but no UIExportedTypesDeclarations.)
 

Join cocoa@apple-dev.groups.io to automatically receive all group messages.