Open AliEasy opened 3 years ago
I will take a look into it. But I can suggest you one thing. As SignalR won't stay connected in the background state, you should disconnect when leaving app and reconnect when coming back or resuming the app. This should be your connection flow I guess.
ok so this is my code
@override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.inactive ||
state == AppLifecycleState.detached) {
print('inactive');
_signalR.stop();
_signalR1.stop();
return;
}
if(state == AppLifecycleState.paused){
_signalR.stop();
print('pause');
_signalR1.stop();
}
if (state == AppLifecycleState.resumed) {
print('resumed');
await _signalR.connect();
// _signalR1.reconnect();
Future.delayed(const Duration(milliseconds: 6000), () {
_signalR1.connect();
});
}
}
at first signalr
stops, but after connecting, the problem occurs
After a couple of hours looking for the problem I found sth interesting
The problem with the above answer is that Im using to separate signalr
s in my application, and so after coming back to application from background I have to reconnect 2 signalr
s
Otherwise if I set up only one signalr
in my app every thing works fine and all I have to do is to stop and resume signalr
between background and foreground like this:
@override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.inactive ||
state == AppLifecycleState.detached) {
print('inactive');
_signalR.stop();
return;
}
if(state == AppLifecycleState.paused){
print('pause');
_signalR.stop();
}
if (state == AppLifecycleState.resumed) {
print('resumed');
await _signalR.connect();
}
}
This problem also occurs when initializing signalr
s for the first time (when opening app for the first time), and my work around for that is to initialize my second signalr
with a delay like below:
initializeInternalSignalR();
Future.delayed(const Duration(milliseconds: 6000), () {
initializeAlarmSignalR();
});
Otherwise signalr
wont Work
But after all in case of reconnecting signalr
s after coming back from background, the Delay trick wouldnt work and signalr
s
wont connect as said in the question
Hi I found a issue in package (so far on ios, not tested on android) At first after initializing
signalr
every thing is fine. But by pressing home button and running app in background and then opening app from background, a connection problem occurs and connection status keep changing without any success connection and continues until app is killed.Here is the log