Daddoon / BlazorMobile

Create full C# driven hybrid-apps for iOS, Android, UWP & Desktop with Blazor!
MIT License
413 stars 55 forks source link

In iOS Mobile app lost session variable data #238

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi @Daddoon

Hope you are doing well......

I use the blazor for the web application, Android app and iOS app. I am facing issue to lost the session variable data in the iOS app when application goes to background or screen lock for 30 min above. Session variable e.g. key or others details.

What I do to share the session variable from main application to Android and iOS application without lost it if takes long time if mobile sleep.

Daddoon commented 2 years ago

The Session and Local Storage is cleared at each app initialization. This is by design on the Web part for this project. However you can store your data directly on the native side, and retrieve it at any time when needed with interop.

See: https://github.com/Daddoon/BlazorMobile/issues/231 See: Read also this part of the doc: https://github.com/Daddoon/BlazorMobile#communication-between-blazor--native

When your code will reach the native service/interface you will have implemented, use any Storage logic you wich to store your data on the native side. When i used this on some project in the past i used SQLite , but you may store anything differently (A file , a native private store...)

ghost commented 2 years ago

Hi @Daddoon I am face issue Webscocket issue when iPhone mobile comes from sleep mode.

The issue message are "blazor mobile not able to connect to native through websocket server execute task" comes when iOS app again use after 30 min or sleep mode.

You provided me above some points, but I always this native approach to share the variables in my application.

Daddoon commented 2 years ago

Do you have this issue on all iOS devices (if you have many) ? Does it happen only on a specific versions ?

I don't maintain this project specifically anymore now as you can, i think, migrate easily to .NET MAUI for Blazor on Mobile. In my opinion the error you are encountering is likely a regression to the iOS version OR if you have updated some NuGet packages references that may behave differently now that could have been used with BlazorMobile.

I think the WebServer does not restart correctly after app restore (but it was working in the past). I don't have a definitive answer nor the time for fixing this.

But you may try some "hackery" and test on your side.

The idea would be, by yourself, to try to override any logic on your side when the app is restored (returning from sleep mode), and try to Restart manually the webserver.

You would use:

BlazorMobile.Services.WebApplicationFactory.ReloadApplication();

(Source code here if needed: https://github.com/Daddoon/BlazorMobile/blob/ec3d6e4dc290fc0e9347f5a894141c0e891fdfe2/src/BlazorMobile/Services/WebApplicationFactory.cs)

ghost commented 2 years ago

Hi @Daddoon Hope you are doing well....

Thank you so much for give me solution. But When I apply.this code on the my App.xml.cs page in the OnResume and OnStart or one of them it not work for the iOS issue. The issue are when the application goes to Sleep or Resume state and we come back to application application loss his native approach variable data.

Please provides me some others solution for that.

Thanks

Daddoon commented 2 years ago

Have you done some debug to test this behavior ? Do you have anything right or wrong while restarting the webserver ?

ghost commented 2 years ago

@Daddoon When I try restart webserver in OnResume() and OnSleep() method then application reload but I loss the native variable data which are store in the application.

But When I kill my application on iOS and click on the icon of app for reopen after this all things working.

I am facing issue when my iPhone goes to sleep mode or resume mode.

Daddoon commented 2 years ago

What do you mean by "You loss the native variable ?" Where are you storing your data ? Wich API ? When the app resume are you still able to communicate with native side ?

ghost commented 2 years ago

Hi @Daddoon Yes, I lost my "native variable data". When I resume the app and come into application then I am not able to communicate with the native side data which are store share variable in application.

Daddoon commented 2 years ago

Sorry, but i have considered that this project is now discontinued. I neither have the time to debug anymore and you have an alternative solution with .NET MAUI that does exactly the same and is supported by Microsoft.

Consider migrating your codebase on this new model. See the README page of this repo.