Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 8380988

Browse files
authored
[connectivity] Fix reachability stream for iOS (#2281)
1 parent 1b5eae5 commit 8380988

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

packages/connectivity/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.5+6
2+
3+
* Fix singleton Reachability problem on iOS.
4+
15
## 0.4.5+5
26

37
* Add an analyzer check for the public documentation.

packages/connectivity/ios/Classes/ConnectivityPlugin.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ @interface FLTConnectivityPlugin () <FlutterStreamHandler, CLLocationManagerDele
2222

2323
@implementation FLTConnectivityPlugin {
2424
FlutterEventSink _eventSink;
25+
Reachability* _reachabilityForInternetConnection;
2526
}
2627

2728
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
@@ -174,12 +175,16 @@ - (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink
174175
selector:@selector(onReachabilityDidChange:)
175176
name:kReachabilityChangedNotification
176177
object:nil];
177-
[[Reachability reachabilityForInternetConnection] startNotifier];
178+
_reachabilityForInternetConnection = [Reachability reachabilityForInternetConnection];
179+
[_reachabilityForInternetConnection startNotifier];
178180
return nil;
179181
}
180182

181183
- (FlutterError*)onCancelWithArguments:(id)arguments {
182-
[[Reachability reachabilityForInternetConnection] stopNotifier];
184+
if (_reachabilityForInternetConnection) {
185+
[_reachabilityForInternetConnection stopNotifier];
186+
_reachabilityForInternetConnection = nil;
187+
}
183188
[[NSNotificationCenter defaultCenter] removeObserver:self];
184189
_eventSink = nil;
185190
return nil;

packages/connectivity/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for discovering the state of the network (WiFi &
33
mobile/cellular) connectivity on Android and iOS.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity
6-
version: 0.4.5+5
6+
version: 0.4.5+6
77

88
flutter:
99
plugin:

0 commit comments

Comments
 (0)