SpecialFolder issues

I can write to SpecialFolder.Documents, but not SpecialFolder.ApplicationSupport or SpecialFolder.Temporary.

Has anyone else had issues with this?

Did you verify the folders exist first?
If not, you need to create them.

Yes.

Is there a documentation available explaining which type to use in which case, or what their specific pros and cons are? In the Xojo documentation I find this list but maybe the Apple documentation has more on that?

Mobile

Mobile has these properties:

  • ApplicationSupport
  • Caches
  • Documents
  • Temporary

Specific paths do not matter much with sandboxing, but you can use these locations to store files that your apps can access.

They’re defined here:

ApplicationSupport = NSApplicationSupportDirectory

Caches = NSCachesDirectory

Documents = NSDocumentDirectory

Temporary = NSItemReplacementDirectory

I know that’s not much help, but you’ll note that the name for Temporary is NSItemReplacementDirectory which gives you a clue.

I just went through the process of figuring out the declares for getting the temporary directory and apparently Apple now suggests a different way to get the temp directory than they did when we Xojo iOS was new.

Here’s a project with that function fleshed out: Download.

Note: Apple asks that you not forget to delete anything that you put in this directory when you are done.

1 Like

Ok. After doing a little digging and consulting of WWDC and some other resources it looks like the conditions for these folders on iOS are:

  • SpecialFolder.Temporary – Items in this directory should be truly temporary. It is not guaranteed to be the same across launches of your app and may even be deleted by the system when your app quits or is sent to the background. I suggest using the example I posted above for this until this gets fixed in the framework.
  • SpecialFolder.Caches – Items to make your app more efficient. It appears that this folder path does not change from launch to launch, but it may be cleared by the system when your app is not in the foreground to free up storage space in low storage conditions.
  • SpecialFolder.ApplicationData – Persistent items associated with your app which are not user-facing. Things like preferences.
  • SpecialFolder.Documents – Persistent items associated with your app which are user-facing. This folder may be visible to users in iTunes or Finder on macOS when the device is plugged in.
3 Likes

This is really helpful, Greg. Thank you for taking the time to investigate.
I’m downloading your project and will implement.

I believe I was using the filters with the proper intention. While SpecialFolder.Documents was working it didn’t feel right to put the preferences there.

As long as you don’t enable FileSharig Documents won’t be available in the finder or iTunes.

I’d expect preferences to be in ApplicationData unless you really want users to be able to access them someday.

I agree. It just wasn’t working.
I’ll try to update with your code samples.

So you can see the contents of SpecialFolder.Documents? From the Finder with phone plugged in? I am not see it. Any hints?

you have to click on the FIleSharing capability.

Thanks. But the app itself is not showing up in the finder window…

And you are USBing it not just using your network?
Is the sidebar visible?

It’s odd you are having trouble with this. Could it be an OS version issue? Can you see the device in iTunes?

Thank you sir! I had to reload or close window and select phone again. Appreciate the patience and have a great weekend!

1 Like

I’ve been putting database files in SpecialFolder.ApplicationData. This is all user data, but it makes no sense to allow access outside the app. Is this correct?

I tend to put read-only files in ApplicationData, like a database that populates a large table that the user selects from.

I put user-generated data in Documents (using JSON these days) which will be read back into the app upon a complete restart.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.