Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS equivalent of accessing Android asset files

I have a Xamarin Android application in which I've bundled up some files as assets and I can access them like this: Android.App.Application.Context.Assets.Open(fileName)).

How would I go about doing this in an iOS application?

like image 749
M. Chris Avatar asked Sep 19 '25 16:09

M. Chris


1 Answers

The NSBundle class is the closest equivalent with using a BundleResource build action:

Example:

var path = NSBundle.MainBundle.BundlePath;
var filePath = Path.Combine(path, "someDataFile.xml");
var someFileContents = File.ReadAllBytes(filePath);

There are also FromBundle overloads on some classes:

var image = UIImage.FromBundle("myimage.png");
like image 100
SushiHangover Avatar answered Sep 21 '25 11:09

SushiHangover