Native File Picker for Android & iOS [Open Source]

Hi there,

I’d like to share my latest plugin, a native file picker for Android & iOS that lets you import/export files from/to various document providers on these platforms.

Asset Store: Native File Picker for Android & iOS | Integration | Unity Asset Store
Also available at: https://github.com/yasirkula/UnityNativeFilePicker
Discord: yasirkula Unity Assets
GitHub Sponsors :coffee:

Enjoy!

4 Likes

This is very useful. Thank you very much for sharing.

Have you looked at implementing the same for Android?

This could be a good starting point:
https://github.com/thedoritos/unimgpicker
Just needs to be generalized to handle more file types.

1 Like

Thanks! The plugin you’ve mentioned probably works similar to NativeGallery.

SimpleFileBrowser works fine on Android so I didn’t consider creating another file picker plugin for Android. User experience may not be as pretty as a native file picker and I might add support for native file pickers using Document Providers in the future but I am not planning to do so anytime soon.

@KibsgaardUnityStudios Added Android support with the latest release.

1 Like

Hello @yasirkula ,
This is very usefull, but somehow i cannot pick a file (files appear greyed out) in IOS even though i filling the file types parameter on NativeFilePicker.PickMultipleFiles(Action, string[ ]).
is there anything i’ve missed?

Thanks :smile:

Are there any error messages in Xcode console and can I see your code?

Hello @yasirkula .
When compiling by Xcode, I have this error:

Undefined symbols for architecture arm64:
“_kUTTagClassFilenameExtension”, referenced from:
+[UNativeFilePicker convertExtensionToUTI:] in NativeFilePicker.o
“_UTTypeCreatePreferredIdentifierForTag”, referenced from:
+[UNativeFilePicker convertExtensionToUTI:] in NativeFilePicker.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How can I fix it ? Thanks.

1 Like

If you’ve disabled automated iOS setup, you must follow these steps: Manual Setup for iOS · yasirkula/UnityNativeFilePicker Wiki · GitHub. If you’ve already done these, does adding SystemConfiguration.framework to “Link Binary With Libraries” in Xcode resolve the issue?

Enabling automated IOS setup solved problem. Sorry i forgot to read readmy )).
Thanks for help.

1 Like

Thank you very much! That is perfect.

Can it work in editor as well?

It doesn’t but I might add support for it later.

When building for iOS the following error occurs during the XCode build:

Libraries/Plugins/NativeFilePicker/iOS/NativeFilePicker.mm(26,24): error: assigning to 'id<UIDocumentPickerDelegate> _Nullable' from incompatible type 'const Class'
        filePicker.delegate = self;
                              ^~~~
Libraries/Plugins/NativeFilePicker/iOS/NativeFilePicker.mm(55,25): error: assigning to 'id<UIDocumentPickerDelegate> _Nullable' from incompatible type 'const Class'
                filePicker.delegate = self;
                                      ^~~~
2 errors generated.
   + [arm64] Linking UnityFramework...
ld: file not found: build/UnityFramework/Release/arm64/Libraries/Plugins/NativeFilePicker/iOS/NativeFilePicker.mm.obj

Toolchain is Unity 2019.4.13f1 / XCode 12

Any ideas how to fix it? Thanks in advance.

You are building it on an actual Mac device, right?

Actually we are building on a windows pc with the iOS project builder. But the XCode SDK that we use is up to date. We are using this project builder tools since years and did not have any similar issues before, so I guess(!) the issue is not related to the tool chain (e.g. your plugin “native gallery” works without any issues).

We also tried the Unity cloud build, which also fails, but with a different error message:

...
▸ ⚠;️  /BUILD_PATH/evospark-gmbh.augmaintenance.default-ios/temp20201203-3737-1dbo8wa/Libraries/Plugins/NativeFilePicker/iOS/NativeFilePicker.mm:3:18: extra tokens at end of #ifdef directive [-Wextra-tokens]
169: ▸ ❌;  Undefined symbols for architecture arm64
170: ▸ ❌;  ld: symbol(s) not found for architecture arm64
171: ▸ ❌;  clang: error: linker command failed with exit code 1 (use -v to see invocation)
...
332: ❌;  Undefined symbols for architecture arm64
333: ❌;  ld: symbol(s) not found for architecture arm64
334: ❌;  clang: error: linker command failed with exit code 1 (use -v to see invocation)
335: ▸ clang: error: linker command failed with exit code 1 (use -v to see invocation)
336: ! build of 'default-ios' failed. ! xcode build failed.
337: publishing finished successfully.
338: Finished: FAILURE

XCode-Version for the cloud build is 11.4.1

The project is only an empty project with nothing else but the native file picker - no other plugins included.

Sorry, my last post was a bit incomplete.
The previously posted error is for the build when ENABLED is set to false.

Wenn ENABLED ist set to true, the following error occurs (again Unity cloud build with XCode 11.4.1):

789: error: exportArchive: exportOptionsPlist error for key 'iCloudContainerEnvironment': expected one of {Development, Production}, but no value was provided
790: Error Domain=IDEFoundationErrorDomain Code=1 "exportOptionsPlist error for key 'iCloudContainerEnvironment': expected one of {Development, Production}, but no value was provided" UserInfo={NSLocalizedDescription=exportOptionsPlist error for key 'iCloudContainerEnvironment': expected one of {Development, Production}, but no value was provided}
791: Error packaging up the application
792: [!] Error packaging up the application
793: ! build of 'default-ios' failed. ! xcode build failed.
794: publishing finished successfully.
795: Finished: FAILURE
1 Like

With the help of @yasirkula I was able to get the build running.
In the NativeFilePicker.mm you have to change all lines with filePicker.delegate = self; into filePicker.delegate = (id) self; (lines 26 and 55).

With this change my local build with the iOS project builder succeeds if I use XCode 12 (SDK 14.2). With an older XCode (SDK 13.2) it still fails.
The cloud build is still not possible, as for the cloud build XCode 12 is not available yet.

Can someone confirm that it depends on the XCode version if the Native File Picker can be build?

Thanks @yasirkula for providing the fix.

Unity Cloud Build and iOS Project Builder issues should be fixed with the latest update on Asset Store. Also added Editor support for most of the functions @UDN_30011711-3d42-4608-a55a-5bf3a3109e16

Hello @yasirkula , thank you for this amazing plugin.

How can i pick the byte[ ] from returned file paths?

Can i use System.IO.File.ReadAllBytes(file)?

I really don’t know if i can read internal android file paths this away.

Thanks in advance
Att

1 Like

Yes, you can use all File functions on that path.