My app is not able to work in offline mode after I disconnected the internet. When I debugged, it failed at line 49(plz visit the screenshot attached) as shown highlighted. Somehow it is getting the realm instance at line 48 even in offline mode, but throwing error 'Object reference not set to an instance of an object' at the next line. How will I achieve the offline functionality from here? My code is in .Net.
Second scenario: I first connected to internet and then opened my app. It opened, then I turned internet off. Then I tested my application features and it was able to work without internet at that time. Even I came back online, it posted all the data that I created in offline mode.
public async static void SubscribeProducts()
{
try
{
App.realmProducts = Realm.GetInstance(App.config);
App.realmProducts.Subscriptions.Update(() =>
{
var products = App.realmProducts.All<Products>()/*.Where(t => !string.IsNullOrEmpty(t.AgentName))*/;
App.realmProducts.Subscriptions.Add(products);
});
await App.realmProducts.Subscriptions.WaitForSynchronizationAsync();
}
catch (Exception ex)
{
}
}
screenshot of code snippet and error
Next observation: while creating the instance and loggin in, it's failing at the login step, since it's in offline mode. But since I kept the block in try catch, it skipped through that block and I am not able to process any offline work. Is it because the login didn't work? Then I can say, atleast one time, my app has to appear online before I can do something. This is not intended I think.
public async static void InitRealms()
{
try
{
var myRealmAppId = "application-2-dfsre";
var app = Realms.Sync.App.Create(myRealmAppId);
var user = await app.LogInAsync(Credentials.EmailPassword("arup@gmail.com", "aruparup"));
config = new FlexibleSyncConfiguration(user);
}
catch (Exception ex)
{
}
}
public async static void SubscribeEntities()
{
realmEntities = Realm.GetInstance(config);
realmEntities.Subscriptions.Update(() =>
{
entities = realmEntities.All<Entities0>()/*.Where(t => !string.IsNullOrEmpty(t.AgentName))*/;
realmEntities.Subscriptions.Add(entities);
});
await realmEntities.Subscriptions.WaitForSynchronizationAsync();
}