4

I've have a Xamarin iOS project with a file that I have marked as a bundle resource. The file is configured in the project like so:

<BundleResource Include="my\folder\file.xyz" />

I've have been using the following to access the file as a stream:

string ext = Path.GetExtension ("file.xyz");
string filenameNoExt = filename.Substring (0, filename.Length - ext.Length);
string path = Path.Combine ("my/folder", filenameNoExt);
var resourcePathname = NSBundle.MainBundle.PathForResource (path, ext.Substring (1, ext.Length - 1));
var fStream = new FileStream (resourcePathname, FileMode.Open);

It won't work on iOS 8. It worked without issue before iOS 8.

I get the following error:

Access to the path "/private/var/mobile/Containers/Bundle/Application/0E6DD32F-4E6F-4E54-B47E-A91060097E16/myapp.app/my/folder/file.xyz" is denied.

What, exactly, do I need to change to get this to work in iOS 8?

sungiant
  • 3,152
  • 5
  • 32
  • 49

1 Answers1

7

Provide also FileAccess.Read when you create the stream. Otherwise it will throw an UnauthorizedAccessException for read-only files.

Krumelur
  • 32,180
  • 27
  • 124
  • 263