Starts in:
1 DAY
23 HRS
10 MIN
0 SEC
Starts in:
1 D
23 H
10 M
0 S
Open Closed

Mobile MAUI if the server is not available #6714


User avatar
0
lszabados@consult2000.hu created
  • ABP Framework version: v8.0.3
  • UI Type: Blazor Server + Mobile MAUI
  • Database System: EF Core (SQL Server)
  • *Tiered (for MVC) or Auth Server Separated (for Angular)**: NO
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hello,

When running the mobile MAUI application, if the application does not reach the server, it will exit with an error. (Android, windows) In reality, it may happen that e.g. there is no internet on the mobile, or even the server address is not correct after installation.

Now, if the server is not reachable, I get Autofac.Core.DependencyResolutionException error message for android and Volo.Abp.Http.Client.AbpRemoteCallException error for windows emulation.

How should this be solved? It would be good if the ABP template provides a ready solution to set the server address and in case the server is not available.

Regards,


3 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello ,

    To enable offline functionality, it's essential to utilize an SQLite database to store data. When the application is online, this data should be synced with the SQLite database. In instances where the network isn't available, operations should rely on the data stored in SQLite. Additionally, an event should be implemented to trigger data updates whenever the network connection is established.

    We will try to provide ready solution for this but currently there is no plan for this.

    Thank you.

  • User Avatar
    0
    lszabados@consult2000.hu created

    Hello,

    I don't want to implement offline operation, but I want the application not to quit if the server is not available, but to say "Server not available". In addition, in this state it should be possible to edit the server address, which is now contained in appsettings.json.

    For an installed Android application, I think this is essential.

    Regards,

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi, AbpApplication can't be initialized without retrieving application-configuration. So, it's not possible to initialize the same application without application configuration. Here are 2 ways to go:

    1 ) You can cache application-configuration once it's retrieved and read application-configuration from local storage if it's not available, and you have to implement offline cases on each page. It's tough and complex way.


    2 ) You can handle it if the backend isn't reachable and show the error page. (In that way application can't be opened without restarting when backend is available again)

    Here the steps to show error in your application:

    • Go to MauiProgram.cs, find the following code block and remove it
    app.Services.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(app.Services);
    
    • Go to App.xaml.cs and initialize it in here and show an error page when it can't be initialized. Change the MainPage = serviceProvider.GetRequiredService<AppShell>() section in theconstructor with the following pattern:
     try
     {
         serviceProvider.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(serviceProvider);
         
         // Regular scenario, everything is fine:
         MainPage = serviceProvider.GetRequiredService<AppShell>();
     }
     catch (Exception ex)
     {
         MainPage = new ContentPage {  Content = new Label { Text = ex.Message } };
    
         // Log the exception with your tracking tool, AppCenter, Sentry, etc.
         // Crashes.TrackError(exception);
     }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06