yasirkula / UnityNativeFilePicker

A native Unity plugin to import/export files from/to various document providers on Android & iOS
MIT License
289 stars 32 forks source link

Not able to pick .GLB file type in iOS #41

Open nextechar-hardik opened 1 year ago

nextechar-hardik commented 1 year ago

Description of the bug

Not able to select .glb file from storage in iOS devices.

Reproduction steps

Use file picker code with following condition if (fileExtension == ".glb" || fileExtension == ".gltf" || fileExtension == ".obj")

its working fine in Editor / Android but not working in iOS , not able to select .glb file.

Platform specs

yasirkula commented 1 year ago

Can I see your code?

nextechar-hardik commented 1 year ago

Okay let me create demo project and will share that here.

yasirkula commented 1 year ago

I only need to see your usage of PickFile function. You can copy your C# code here.

VincentMarnier commented 4 months ago

Hello.

First of all, thanks for the hard work and the code quality. I have dug a bit to understand what UnityNativeFilePicker was doing exactly and it is very clear.

I am having the same issue so I am updating this post as I assume @nextechar-hardik wont.

I have an abstraction layer on top of UnityNativeFilePicker so I can use different methods to pick files (or pick files on other systems), so I won't give the full code as it is not related, but it ends up calling the following:

string[] extensions = new [] {
    NativeFilePicker.ConvertExtensionToFileType("png"),
    NativeFilePicker.ConvertExtensionToFileType("jpg"),
    NativeFilePicker.ConvertExtensionToFileType("jpeg"),
    NativeFilePicker.ConvertExtensionToFileType("gltf"),
    NativeFilePicker.ConvertExtensionToFileType("glb")
}
NativeFilePicker.PickFile(path => Debug.Log(path), extensions);

Only png, & jpeg files can be picked. GLTF & GLB are not displayed.

I found the following post that might be useful: https://developer.apple.com/forums/thread/716575

VincentMarnier commented 4 months ago
Previous post > It seems a deprecated method is used to acquire UTType: > https://github.com/yasirkula/UnityNativeFilePicker/blob/da3f797fd86ca715236632d8d8f0d8ae3d8f4578/Plugins/NativeFilePicker/iOS/NativeFilePicker.mm#L100 > The initializer is now the correct way to do this: > https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/init(tag:tagclass:conformingto:) > > I made a test in xcode, without deploying to anything. Using a basic Swift project: > Capture d’écran 2024-06-18 à 15 02 27 > > Using the new initializer seems to fix the issue.

Nevermind, it works with the deprecated method too. My code was just garbage. I'll try to find another answer to why it fails then.

yasirkula commented 4 months ago

GLB and GLTF don't exist in the filetype lists I've posted: https://github.com/yasirkula/UnityNativeFilePicker?tab=readme-ov-file#a-importing-files. The only possible solution is to allow picking all files and then check the returned files' extensions in the callback function.