sungiant
sungiant

Reputation: 3222

Xamarin iOS 8 Bundle Resource - Access to the path is denied

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?

Upvotes: 4

Views: 2545

Answers (1)

Krumelur
Krumelur

Reputation: 33048

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

Upvotes: 7

Related Questions