Skip to content

How can I use ConvertExtensionToFileType for custom extensions? #7

Open

Description

@hippogamesunity

Hi!
For example, I have .psp extension in my app.
I've also set Custom Types:
image

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.

Activity

  1. yasirkula commented on Jan 14, 2021

    @yasirkula
    Owner

    What is the output of NativeFilePicker.ConvertExtensionToFileType("psp")?

  2. hippogamesunity commented on Jan 15, 2021

    @hippogamesunity
    Author

    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.

  3. yasirkula commented on Jan 15, 2021

    @yasirkula
    Owner

    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: #1. Maybe it will resolve the issue, despite its mentioned downside.

  4. hippogamesunity commented on Jan 15, 2021

    @hippogamesunity
    Author

    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.
    Снимок экрана 2021-01-15 в 21 59 55
    I'll try the suggested workaround (still in progress).

  5. hippogamesunity commented on Jan 15, 2021

    @hippogamesunity
    Author

    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!

  6. yasirkula commented on Jan 15, 2021

    @yasirkula
    Owner

    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.

  7. orangeagain commented on Aug 13, 2021

    @orangeagain

    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.

  8. added
    bugSomething isn't working
    and removed
    bugSomething isn't working
    on Jan 15, 2022
  9. andysdds commented on Aug 22, 2022

    @andysdds

    I fixed it by changing UTIs[I] to Your IdentifierId like "com.yasirkula.nativefilepicker" and it work.

    [allowedUTIs addObject:[NSString stringWithUTF8String:UTIs[i]]];

  10. yasirkula commented on Aug 22, 2022

    @yasirkula
    Owner

    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?

  11. andysdds commented on Aug 22, 2022

    @andysdds

    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)

  12. yasirkula commented on Aug 22, 2022

    @yasirkula
    Owner

    In the example code, did you pass the custom file extension to pdfFileType = NativeFilePicker.ConvertExtensionToFileType( "pdf" );?

  13. andysdds commented on Aug 23, 2022

    @andysdds

    Yes, I did.

    Edit:If I don't hardcode the "com.yasirkula.nativefilepicker" in NativeFilePicker.PickFile , pdfFileType will be empty

  14. orange3134 commented on Mar 21, 2023

    @orange3134

    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.

  15. orange3134 commented on Mar 21, 2023

    @orange3134

    Solved, Conforms To needed to be set to "public.data".

  16. marvpaul commented on Mar 27, 2023

    @marvpaul

    FYI: if you want to import custom filetypes eg on Android, I found this plugin doing the job: https://github.com/keiwando/nativefileso

  17. yasirkula commented on Mar 27, 2023

    @yasirkula
    Owner

    One should inspect its license before using it, I'd recommend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions