Skip to content

Instantly share code, notes, and snippets.

@ozzieperez
Last active March 3, 2019 19:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzieperez/5cb5ecc9960123e35fb0 to your computer and use it in GitHub Desktop.
Save ozzieperez/5cb5ecc9960123e35fb0 to your computer and use it in GitHub Desktop.
Xamarin.iOS - Get Special Folder Directory
public class IOHelper
{
public enum IosSpecialFolder
{
Documents,
Library,
Cache,
Preferences,
Tmp
}
// This method takes into account the check for the update in iOS 8.
// https://developer.apple.com/library/ios/technotes/tn2406/_index.html
public static string GetSpecialFolderPath(IosSpecialFolder specialFolder)
{
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
//is it above or equal to iOS 8?
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
documents = NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User) [0].Path;
}
switch (specialFolder) {
case IosSpecialFolder.Documents:
return documents;
case IosSpecialFolder.Cache:
return Path.Combine (documents, "..", "Library", "Caches");
case IosSpecialFolder.Library:
return Path.Combine (documents, "..", "Library");
case IosSpecialFolder.Preferences:
return Path.Combine (documents, "..", "Library", "Preferences");
case IosSpecialFolder.Tmp:
return Path.Combine (documents, "..", "tmp");
default:
return string.Empty;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment