Help with UTIs and UIDocumentPickerViewController


Rick Aurbach
 

Sorry, Alex.  As usual, publishing this allowed me to see my mistake.

First of all, the "msug" thing has to do with the output file, not the input file.

Secondly, the problem was in the code -- I was specifying public.comma-delimited-values-text, but it SHOULD have been public.comma-separated-values-text.

Sorry to waste your time.

Rick


Alex Zavatone
 

FYI, you might want to heck out the expected file types in UTTypes.h

It’s here.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Headers/UTType.h


Though this is for iOS, it might help.  Scroll down to "What is a Uniform Type Identifier?"


For a little backgorund info.

Below is this info.

init(forOpeningFilesWithContentTypes allowedContentTypes: [String]?)




Below that is this.

Greyed Out Icon: The Solution

//UIDocumentViewControllerlet utis = func getUTTypeCreateAllIdentifiers(for: "gpx")
let viewController = UIDocumentViewController(forOpeningFilesWithContentTypes: utis)
//UIDocumentPickerViewControllerlet viewController = UIDocumentPickerViewController(documentTypes: utis, in: .open)


I hope this helps.

Alex Zavatone



On Feb 9, 2021, at 3:50 PM, Alex Zavatone via groups.io <zav@...> wrote:

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.)
 



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.)