UnityNativeFilePicker
UnityNativeFilePicker copied to clipboard
How can I use ConvertExtensionToFileType for custom extensions?
Hi!
For example, I have .psp extension in my app.
I've also set Custom Types:

Then I'm using allowedFileTypes.Add(NativeFilePicker.ConvertExtensionToFileType("png")); allowedFileTypes.Add(NativeFilePicker.ConvertExtensionToFileType("jpg")); ... allowedFileTypes.Add(NativeFilePicker.ConvertExtensionToFileType("psp"));
As a result, I can't pick .psp files both on iOS and Android, they are greyed. On Android - it seem's custom types are simply unsupported.
What is the output of NativeFilePicker.ConvertExtensionToFileType("psp")?
Hello! It returns com.pixelstudio.psp. I've also tried removing all other extensions and using only "com.pixelstudio.psp" directly without ConvertExtensionToFileType. Still unable to pick psp file. Is it correct to use public.image as Conforms To in my case when psp is just a custom binary file that only my app can read? Thank you for your time.
Does changing public.image to public.data make any difference? If not, please give the Manual Setup a shot: https://github.com/yasirkula/UnityNativeFilePicker/wiki/Manual-Setup-for-iOS
If it still doesn't work, check out the Document Types that is mentioned here: https://github.com/yasirkula/UnityNativeFilePicker/issues/1. Maybe it will resolve the issue, despite its mentioned downside.
At first I want to note that my type is both exported and imported. But if I check "Is Exported" it will only appear in Xcode in Exported Type Identifiers. I think there should be two checkboxes in Custom Types declaration window. As a workaround it seems I have to specify my item twice (as imported and as exported). I've also tried manual setup but it didn't work for me.
I'll try the suggested workaround (still in progress).
Unfortunately I was enable to make this functionality work. For unknown reason "additional imported type identifier properties" are empty after Unity build and reset to null after building in Xcode even if I specify them manually. I wonder if you could accept my paid request to prepare and upload dummy Xcode project that will open files with .psp extension, so I could use it as a working example. Thank you!
I can't because I don't have access to Mac workstation. Even if I did, I don't think I could help you because all I did during my own tests was filling the properties of Window-NativeFilePicker Custom Types. I didn't do anything special.
I'd like to quote "Is Exported"s tooltip:
If this type is owned by your app (i.e. exclusive to your app), set this value to true. If another app generates files of this type and your app is merely importing/modifying them, set this value to false.
So it isn't about app's capability of importing/exporting those files. Don't declare 2 custom types for the same extension. Simply have a single one and enable its Is Exported option. You can also try disabling that option.
I add this code to Info.plist:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>this is CFBundleTypeName</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.DefaultCompany.vrm079.custom</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>vrm model file</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>com.DefaultCompany.vrm079.custom</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>vrm</string>
</array>
</dict>
</dict>
<dict/>
</array>
works for me, If you have any problem please @ me.
I fixed it by changing UTIs[I] to Your IdentifierId like "com.yasirkula.nativefilepicker" and it work.
https://github.com/yasirkula/UnityNativeFilePicker/blob/320d444af1241e2f196ef64c87f309494c4e83e9/Plugins/NativeFilePicker/iOS/NativeFilePicker.mm#L187
Passing "com.yasirkula.nativefilepicker" to NativeFilePicker.PickFile should've done the same thing because allowedFileTypes parameter is passed directly to the native _NativeFilePicker_PickFile function. Did you try passing hardcoded "com.yasirkula.nativefilepicker" (your own UTI) to NativeFilePicker.PickFile function's allowedFileTypes parameter?
Yeah, it work. In your example code, the pdfFileType still show nothing, and the file will grey out, if I don't hardcoded "com.yasirkula.nativefilepicker" (I am using custom file extension)
In the example code, did you pass the custom file extension to pdfFileType = NativeFilePicker.ConvertExtensionToFileType( "pdf" );?
Yes, I did.
Edit:If I don't hardcode the "com.yasirkula.nativefilepicker" in NativeFilePicker.PickFile , pdfFileType will be empty
I have the same problem. I am trying to use this to import a BVH file. I have tried orangeagain's method and andysdds's method, but after opening the file picker, the file is grayed out and cannot be selected.
Solved, Conforms To needed to be set to "public.data".
FYI: if you want to import custom filetypes eg on Android, I found this plugin doing the job: https://github.com/keiwando/nativefileso
One should inspect its license before using it, I'd recommend.