Native File Picker for Android & iOS [Open Source]

Hello!! I really love this asset and it helps a lot for my program since im still a beginner!! Thank you!!

I have a (stupid maybe) question. I noticed on your example code section on GitHub that you use several if-elseif to deal with different file types.

Is that the only way to do it, like adding a huge list of if-elseif to handle each one of them? or is there way to do one if statement that allow user to pick any type of files? Thanks!!

If your app can handle any file type, then you may want to use SimpleFileBrowser instead. Regardless, allowedFileTypes for any file type on Android should be */* and on iOS should be [public.item, public.content] (an array of 2 strings).

Thanks for the great plugin!

Can it be used on iOS to pick any file from the photo gallery? I think right now its tied to icloud storage?

I wish Photos would be included in list of apps displayed by UIDocumentPickerController on iOS but unfortunately it isn’t. I don’t think it is possible to pick media from Photos with this plugin. You can have a look at NativeGallery.GetMixedMediaFromGallery, if you wish.

I’m getting the following error when using the cloud build for iOS:

17326: +-------------+-------------------------------+
17327: |              Build environment              |
17328: +-------------+-------------------------------+
17329: | xcode_path  | /APPLICATION_PATH/Xcode12_2_0.app |
17330: | gym_version | 2.170.0                       |
17331: | sdk         | iPhoneOS14.2.sdk              |
17332: +-------------+-------------------------------+
17333: ▸       +[UNativeFilePicker convertExtensionToUTI:] in NativeFilePicker.o
17334: ▸   "_UTTypeCreatePreferredIdentifierForTag", referenced from:
17335: ▸       +[UNativeFilePicker convertExtensionToUTI:] in NativeFilePicker.o
17336: ▸ ld: symbol(s) not found for architecture arm64
17337: ▸ clang: error: linker command failed with exit code 1 (use -v to see invocation)

Got latest plugin files from assetstore.

If automated setup is disabled, you need to add MobileCoreServices.framework to “Link Binary With Libraries” list. I unfortunately don’t know if there is a way to do it inside Player Settings.

I have it enabled

Does inserting pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-framework SystemConfiguration" ); to this line resolve the issue? If not, can you reproduce the issue on a new Unity project with Cloud Build?

That did get it a little bit further, now I’m stuck at:

1492: ▸ Code Signing Error: Provisioning profile "Provision profile xxxxxxxx" doesn't include the com.apple.developer.icloud-container-identifiers and com.apple.developer.icloud-services entitlements and doesn't match the entitlements file's value for the com.apple.developer.ubiquity-container-identifiers entitlement.
1493: ▸ Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 14.2'
1494: ▸ Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 14.2'
1495: ! build of 'default-ios' failed. ! xcode build failed.
1496: publishing finished successfully.
1497: Finished: FAILURE

I have added an iCloud container, although from this point I have not much experience in iOS:

6959651--819596--upload_2021-3-22_10-6-54.png

I also regenerated the appropriate files for the build server and reuploaded them, no idea if it was needed but did it anyway.

Thanks for the help by the way!

Well, does switching to “Include CloudKit support” make any differentce? I wonder if you can reproduce this issue on a new project with default Player Settings and Cloud Build settings but only enabling NativeFilePicker’s automated setup?

In my case I have this same error when doing manual setup, app works fine with automatic but we have another plugin we need to use which is not working when we use automatic File picker postbuild settings

**Edit I just made a fresh project to test the manual IOS setup out and came out with the same error so I made an issue here on github
https://github.com/yasirkula/UnityNativeFilePicker/issues/9
Thanks for your work on this fantastic plugin

@Luchunpen_0 I found the fix for the manual setup!

In the guide for manual steps it says:
“add MobileCoreServices.framework to Link Binary With Libraries list in Build Phases”, this is not clear as the screenshots show the Unity-Iphone Target selected on the left, one would assume you link the MobileCoreServices.framework to there - but you actually need to link it to the target ‘UnityFramework’ in that target’s Build Phases - Link Binary With Libraries list.

6978761--823211--Screenshot 2021-03-26 at 19.37.41.jpg

See the issue and full explanation here:
https://github.com/yasirkula/UnityNativeFilePicker/issues/9#issuecomment-808472691

Using the example for PDF here on IOS, I’m using the asset PDF Renderer from Unity asset store and passing it the path of the pdf from the example code you have but it’s not working, do I need to do something with the ’
new string[ ] { pdfFileType } );’ part of the call instead of using the string ‘path’?

You don’t need anything else. You can insert your code at Debug.Log( "Picked file: " + path ); line of the example code. Are there any error messages in Xcode console? Can it also be possible that PDF Renderer doesn’t support some PDF files?

I meant to delete my post when I realised I was being very silly and had a silent error before the pdf reader got the string I was passing it, but my internet here died. It worked exactly as you said!

1 Like

My Android build is fine and native file picker works correctly however the IOS build fails with the following errors:
ld: warning: arm64 function not 4-byte aligned: _unwind_tester from /Users/simonbooth/Desktop/Projects/AppleBlossumIOS/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
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)
ld: warning: arm64 function not 4-byte aligned: _unwind_tester from /Users/simonbooth/Desktop/Projects/AppleBlossumIOS/Libraries/libiPhone-lib.a(unwind_test_arm64.o)
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)
I’m using XCode 12.3 and Unity 2019.4
Any suggestions of how to fix this?

Did you complete the iOS setup: GitHub - yasirkula/UnityNativeFilePicker: A native Unity plugin to import/export files from/to various document providers on Android & iOS

hello @yasirkula I’m running into issues trying to open a PDF on android in it’s internal PDF viewing options(photos/gallery/etc) stored locally in my unity project in Streaming Assets folder. Would you happen to have a plugin or know of a solution to solve this problem? I’ve found solutions for downloading and then opening. But am hitting a wall with trying to open a file that was built into it initially.

Thank you for any assistance you can provide!

I don’t have a plugin for viewing PDF files but the problem you are encountering is probably related to storing the PDF files inside StreamingAssets. On Android, these files are stored inside the APK file, so they are not really files in the filesystem. They must be extracted from the APK first. You can do it via WWW (google should help), UnityWebRequest or 3rd party assets.

Hello friend! I love your assets.
I want to pick mp3 file from mobile and save the path. Like your amazing Native Gallery.
How can I do this, please?

1 Like