NASA Sapce Apps Challenge
Update [Dec-2014]: It seems that the Xamarin iOS 8.4 update resolves this issue, since Environment.GetFolderPath has been changed accordingly 😃.
With the release of iOS 8 Apple changed the way we have to access folders and documents. Apple reference
For iOS, Xamarin uses the following to get the documents folder on iOS:
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Since Xamarin hasn't changed the logic behind Environment.GetFolderPath(), this will no longer work on iOS 8. And when publishing to the app store you might get the following error log back from apple:
LocalStorageService.FileChecks: Error: Access to the path "/var/mobile/Documents/files" is denied. - at
System.IO.Directory.CreateDirectoriesInternal
Unhandled managed exception: One or more errors occurred (System.AggregateException)
A simple fix is to use the following code instead of the one above:
var documents = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0];
The MvvmCross File plugin hasn't been updated yet to use the new way of getting the correct path. When looking at the MvxTouchFileStore.cs file, it shows that it uses the pre iOS 8 way.
Since this hasn't been changed in the plugin yet, we resolved this issue by creating a custom MvxFileStore for iOS:
public class MvxCustomTouchFileStore : MvxFileStore
{
public const string ResScheme = "res:";
protected override string FullPath(string path)
{
if (path.StartsWith(ResScheme))
return path.Substring(ResScheme.Length);
var returnPath = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0];
return Path.Combine(returnPath.Path, path);
}
}
and registering in the Setup.cs for iOS in the CreateApp() as follows:
Mvx.RegisterType<IMvxFileStore, MvxCustomTouchFileStore>();
Hope this helps!