Last active
March 3, 2019 19:23
-
-
Save ozzieperez/5cb5ecc9960123e35fb0 to your computer and use it in GitHub Desktop.
Xamarin.iOS - Get Special Folder Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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