using xamarin forms v.3.1 and akavache v5 + akavache.sqlite3 v5.
in app.xaml.cs I initialized akavache
BlobCache.ApplicationName = "EF_Cache";
BlobCache.EnsureInitialized();
And to cache data i use localmachine
await BlobCache.LocalMachine.InsertObject<List<int>>("FavouriteTeams", FavouriteTeam, TimeSpan.FromDays(300));
To retrieve data i do
var FavouritesList = await BlobCache.LocalMachine.GetObject<List<int>>("FavouriteTeams");
The following code works fine in android devices with no issue but when i tried it on ios device/simulator it fails with no errors, the getobject<> just return null when restarting the app.
is there any thing is missing or an extra thing should be configured in ios apps in properties or info.plist.
What probably happens is that your Akavache libraries for saving to local machine gets "optimized out" by the linker.
Basically, what that means is that the compiler sees no direct reference from your iOS project to the DLL that is needed to save something to disc and removes it as an optimization. The way Akavache handles it is to fail silently back into in-memory mode.
To get around this, you need to include a class that makes some dummy code references to the classes in the assemblies that are otherwise "linked out". You can find it, and more info on the projects' GitHub.
Add this class to your iOS project, it's also best to add it to your Android project.
public static class LinkerPreserve
{
static LinkerPreserve()
{
var persistentName = typeof(SQLitePersistentBlobCache).FullName;
var encryptedName = typeof(SQLiteEncryptedBlobCache).FullName;
}
}
After adding this, the problem should be resolved.