Access denied using mvxfilestore, mvvmcross annd xamarin touch ios 8.1
My app has just deviated from apple and I believe it might be because they change for testing with ios 8.1. However, there is no way I can reproduce the error. Their chrash report talks about applications on startup.
The exception (there is a crash log) seems to come from
<Warning> Unhandled managed exception: Access to the path "/var/mobile/Documents/settings" is denied. (System.UnauthorizedAccessException)
which is taken from
Cirrious.MvvmCross.Plugins.File.MvxFileStore.WriteFileCommon
I am using the mvvmcross 3.11 MvxFileStore plugin. Ios7 deployment target, 8.1 ios sdk.
I am surfing the web and some states of the Document Directory have moved to iOS 8 and this might throw an exception. But I can't wrap my head in that I can't reproduce this error.
Does anyone have a similar issue, suggestion to fix it, or figure out how to reproduce their crash.
Everyone is welcome.
Update:
The post suggests the following fix
int SystemVersion = Convert.ToInt16(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]);
if (SystemVersion >= 8)
{
var documents = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0].Path;
filename = Path.Combine(documents, sFile);
}
else
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // iOS 7 and earlier
filename = Path.Combine(documents, sFile);
}
I tried to add it to our project. We used MvxFileStore to create the path to the settings file
var filestore = Mvx.Resolve<IMvxFileStore>();
string path = filestore.PathCombine(filestore.NativePath (string.Empty), FILENAME);
We will now define the following
var filestore = Mvx.Resolve<IMvxFileStore>();
string path = this.DocsDir() + "/" + FILENAME;
public string DocsDir ()
{
var version = int.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]);
string docsDir = "";
if (version>=8) {
var docs = NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User) [0];
docsDir = docs.Path;
Console.WriteLine("ios 8++ "+docsDir);
} else {
docsDir = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
Console.WriteLine("ios 7.1-- " + docsDir);
}
return docsDir;
}
I will resubmit my application and post the result.
source to share