You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UnauthorizedAccessException for system folders on Mac OS #66
Hi! I'm testing the plugin on Mac OS and there is an issue with UnauthorizedAccessException when writing to the Root drive.
The situation is:
the app can list system drives and open files
the app can't write to Root or Root/Users (UnauthorizedAccessException)
when I'm trying to move files to Root or Root/Users with Finder, it's asks for a user password (so I think it's considered as secured pathes)
Showing this exception to users blocks me from passing the App Store review, so I'm looking for a workarounds to hide drives or hide inaccessible locations maybe.
Reproduction steps
save any file to the Root drive on Mac OS
Platform specs
Any Unity, any Mac
Additional info
The app asks for permissions to Documents when starting the first time.
First thing I could think of is, every time the path changes, we check for write access in that directory and if we don't have access, disable the Save button. I'll probably give it a shot sometime soon.
All previous errors were from an old x64 Mac.
On the latest Mac OS the plugin doesn't work at all due to sandbox, all pathes are incorrect (like Documents and Desktop).
As you see, these paths are similar to iOS, so I can suggest Mac sandboxing is similar to iOS. BTW you can't send an app to review without adding the Sandbox capability in Xcode. At the same time, even with this feature enabled, you can't test a sandboxed app by running from Xcode. It gets really sandboxed only after downloaded from the App Store. Also I'm noob in Mac OS)
@hippogamesunity@manituan If I were to add a "Browse..." button that allows the user to pick a directory using Mac's native file picker (upon completion, user will be able to browse that folder's contents using SimpleFileBrowser), do you think App Store Review team would object with the reason "if you're gonna show the native dialog anyways, then do everything with the native dialog; why show a uGUI dialog and native dialog together"?
I'd personally prefer the native dialog over uGUI dialog but there are already several native file browser plugins and some users would prefer showing their customized uGUI dialog (e.g. to display a World Space file browser). In any case, the solution will be either a fully native dialog experience or a combination of native+uGUI dialogs as I've described in my first paragraph.
i fixed it here is the code
`using UnityEngine;
using System.Collections;
using System.IO;
using SimpleFileBrowser;
public class FileBrowserTest : MonoBehaviour
{
// Warning: paths returned by FileBrowser dialogs do not contain a trailing '' character
// Warning: FileBrowser can only show 1 dialog at a time
void Start()
{
// Set filters (optional)
// It is sufficient to set the filters just once (instead of each time before showing the file browser dialog),
// if all the dialogs will be using the same filters
FileBrowser.SetFilters( true, /*new FileBrowser.Filter( "text", ".json", ".txt" ),*/ new FileBrowser.Filter( "Text Files", ".txt", ".pdf" ) );
// Set default filter that is selected when the dialog is shown (optional)
// Returns true if the default filter is set successfully
// In this case, set Images filter as the default filter
FileBrowser.SetDefaultFilter( ".json" );
// Set excluded file extensions (optional) (by default, .lnk and .tmp extensions are excluded)
// Note that when you use this function, .lnk and .tmp extensions will no longer be
// excluded unless you explicitly add them as parameters to the function
FileBrowser.SetExcludedExtensions( ".lnk", ".tmp", ".zip", ".rar", ".exe" );
// Add a new quick link to the browser (optional) (returns true if quick link is added successfully)
// It is sufficient to add a quick link just once
// Name: Users
// Path: C:\Users
// Icon: default (folder icon)
FileBrowser.AddQuickLink( "Users", "C:\\Users", null );
// !!! Uncomment any of the examples below to show the file browser !!!
// Example 1: Show a save file dialog using callback approach
// onSuccess event: not registered (which means this dialog is pretty useless)
// onCancel event: not registered
// Save file/folder: file, Allow multiple selection: false
// Initial path: "C:\", Initial filename: "Screenshot.png"
// Title: "Save As", Submit button text: "Save"
// FileBrowser.ShowSaveDialog( null, null, FileBrowser.PickMode.Files, false, "C:\\", "Screenshot.png", "Save As", "Save" );
// Example 2: Show a select folder dialog using callback approach
// onSuccess event: print the selected folder's path
// onCancel event: print "Canceled"
// Load file/folder: folder, Allow multiple selection: false
//Initial path: default (Application.PersistentDataPath), Initial filename: empty
// Title: "Select Folder", Submit button text: "Select"
// FileBrowser.ShowLoadDialog( ( paths ) => { Debug.Log( "Selected: " + paths[0] ); },
// () => { Debug.Log( "Canceled" ); },
// FileBrowser.PickMode.Folders, false, null, null, "Select Folder", "Select" );
// Example 3: Show a select file dialog using coroutine approach
StartCoroutine( ShowLoadDialogCoroutine() );
}
IEnumerator ShowLoadDialogCoroutine()
{
// Show a load file dialog and wait for a response from user
// Load file/folder: file, Allow multiple selection: true
// Initial path: default (Documents), Initial filename: empty
// Title: "Load File", Submit button text: "Load"
yield return FileBrowser.WaitForLoadDialog( FileBrowser.PickMode.Files, true, Application.persistentDataPath, null, "Select Files", "Load" );
// Dialog is closed
// Print whether the user has selected some files or cancelled the operation (FileBrowser.Success)
Debug.Log( FileBrowser.Success );
if( FileBrowser.Success )
OnFilesSelected( FileBrowser.Result ); // FileBrowser.Result is null, if FileBrowser.Success is false
}
void OnFilesSelected( string[] filePaths )
{
// Print paths of the selected files
for( int i = 0; i < filePaths.Length; i++ )
Debug.Log( filePaths[i] );
// Get the file path of the first selected file
string filePath = filePaths[0];
// Read the bytes of the first file via FileBrowserHelpers
// Contrary to File.ReadAllBytes, this function works on Android 10+, as well
byte[] bytes = FileBrowserHelpers.ReadBytesFromFile( filePath );
// Or, copy the first file to persistentDataPath
string destinationPath = Path.Combine( Application.persistentDataPath, FileBrowserHelpers.GetFilename( filePath ) );
FileBrowserHelpers.CopyFile( filePath, destinationPath );
}
@Nuker9999999999 This issue occurs on Mac OS when App Sandbox is enabled. The operating system throws errors while attempting to read contents of directories, so file browser simply stops functioning. Your solution may be related to another issue.
Activity
hippogamesunity commentedon May 26, 2022
yasirkula commentedon May 26, 2022
First thing I could think of is, every time the path changes, we check for write access in that directory and if we don't have access, disable the Save button. I'll probably give it a shot sometime soon.
hippogamesunity commentedon May 26, 2022
Thanks for your reply! Here is another screenshot from the app store reviewer team.

yasirkula commentedon May 27, 2022
What seems to be the issue in this screenshot?
hippogamesunity commentedon May 27, 2022
I mean the error may occur not only for the Root drive, but for others as well.
Btw I've found code to comment to hide drives (as a workaround).
hippogamesunity commentedon May 28, 2022
Another similar exception when listing files (not saving as before).

hippogamesunity commentedon May 28, 2022
All previous errors were from an old x64 Mac.

On the latest Mac OS the plugin doesn't work at all due to sandbox, all pathes are incorrect (like Documents and Desktop).
yasirkula commentedon May 29, 2022
Thanks again for the feedback! I didn't know about sandboxing, will google it while working on a bugfix for this issue.
hippogamesunity commentedon May 29, 2022
As you see, these paths are similar to iOS, so I can suggest Mac sandboxing is similar to iOS. BTW you can't send an app to review without adding the Sandbox capability in Xcode. At the same time, even with this feature enabled, you can't test a sandboxed app by running from Xcode. It gets really sandboxed only after downloaded from the App Store. Also I'm noob in Mac OS)
hippogamesunity commentedon May 29, 2022
Sorry to bothering you, but I'm trying to provide as much info as I have. Thanks!
yasirkula commentedon Jul 26, 2022
Note to self: useful links about app sandboxing:
Checking if directory is writeable -natively-:
Writing Mac OS native plugins:
Added CheckWriteAccessToDestinationDirectory property (#66)
manituan commentedon Jul 10, 2023
Hi, we're facing this issue in our project and I'm wondering if you're still planning on fixing this issue. Thanks.
yasirkula commentedon Jul 10, 2023
My schedule unfortunately won't allow me to fix this issue soon. I'm planning to work on this at some point but not soon.
yasirkula commentedon Sep 1, 2024
@hippogamesunity @manituan If I were to add a "Browse..." button that allows the user to pick a directory using Mac's native file picker (upon completion, user will be able to browse that folder's contents using SimpleFileBrowser), do you think App Store Review team would object with the reason "if you're gonna show the native dialog anyways, then do everything with the native dialog; why show a uGUI dialog and native dialog together"?
I'd personally prefer the native dialog over uGUI dialog but there are already several native file browser plugins and some users would prefer showing their customized uGUI dialog (e.g. to display a World Space file browser). In any case, the solution will be either a fully native dialog experience or a combination of native+uGUI dialogs as I've described in my first paragraph.
Nuker9999999999 commentedon Mar 3, 2025
i fixed it here is the code
`using UnityEngine;
using System.Collections;
using System.IO;
using SimpleFileBrowser;
public class FileBrowserTest : MonoBehaviour
{
// Warning: paths returned by FileBrowser dialogs do not contain a trailing '' character
// Warning: FileBrowser can only show 1 dialog at a time
}`
yasirkula commentedon Mar 3, 2025
@Nuker9999999999 This issue occurs on Mac OS when App Sandbox is enabled. The operating system throws errors while attempting to read contents of directories, so file browser simply stops functioning. Your solution may be related to another issue.