iosairios-app-extensionfile-management

How to access a file in a private/var folder?


I got a path that looks like this:

/private/var/mobile/Containers/Shared/AppGroup/D4A4F193-4125-406F-9A85-2B301F233D7E/image0.jpg

However when I check for existence (file.exists) it always returns false.

The full path I try to open is the same as before but adding file:// before it, so it ends up like this:

file:///private/var/mobile/Containers/Shared/AppGroup/D4A4F193-4125-406F-9A85-2B301F233D7E/image0.jpg

When doing app extensions apparently the file is shared in that folder. Tried File.applicationDirectory, File.documentsDirectory and File.storageDirectory, is there any other special place or way to retrieve the file?


Solution

  • In the end what I forgot to add was the correct entitlements to my app descriptor, allowing me to access the AppGroup folder.

    The whole process is detailed here:

    http://easynativeextensions.com/sharing-files-between-an-air-app-and-an-ios-extension/#step_3