Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignalR disconnects when put iOS app in background #76

Open
nayanAubie opened this issue Feb 2, 2024 · 3 comments
Open

SignalR disconnects when put iOS app in background #76

nayanAubie opened this issue Feb 2, 2024 · 3 comments

Comments

@nayanAubie
Copy link

nayanAubie commented Feb 2, 2024

  • I followed the exact code mentioned in the example project.
  • When I put the iOS app in the background for around 30 seconds, SignalR disconnects automatically and when I back the app in the foreground again, it shows the log of Reconnecting and Reconnected.
  • I've used an iPhone 11 with the release mode app.
@umairali4433
Copy link

i was facing the same issue no one helped so what i did was i just created listner for every 3 second if my hub is disconnected then do reconnect sample code:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:signalr_core/signalr_core.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('HubConnection Status Checker'),
),
body: Center(
child: HubConnectionStatusChecker(),
),
),
);
}
}

class HubConnectionStatusChecker extends StatefulWidget {
@OverRide
_HubConnectionStatusCheckerState createState() => _HubConnectionStatusCheckerState();
}

class _HubConnectionStatusCheckerState extends State {
late HubConnection _hubConnection;
late Timer _timer;

@OverRide
void initState() {
super.initState();

// Initialize your HubConnection here
_hubConnection = HubConnectionBuilder()
  .withUrl('your_hub_connection_url')
  .build();

// Start checking the connection status every second
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
  // Check the connection status
  if (_hubConnection.state == HubConnectionState.Connected) {
    print('HubConnection is connected');
  } else {
    print('HubConnection is not connected');
    // Optionally, try to start the connection again
    // _hubConnection.start();
  }
});

}

@OverRide
void dispose() {
// Cancel the timer and dispose the HubConnection
_timer.cancel();
_hubConnection.stop();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return Text('Checking HubConnection status...');
}
}

and it worked perfectly now i am not facing this issue

@os01ri
Copy link

os01ri commented Feb 26, 2024

facing the same issue in android devices

@xaldarof
Copy link

facing the same issue in android and iOS devices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants