[connectivity] Fix reachability stream for iOS (#2281)
diff --git a/packages/connectivity/CHANGELOG.md b/packages/connectivity/CHANGELOG.md
index 17e49e2..0e1ea81 100644
--- a/packages/connectivity/CHANGELOG.md
+++ b/packages/connectivity/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.4.5+6
+
+* Fix singleton Reachability problem on iOS.
+
## 0.4.5+5
* Add an analyzer check for the public documentation.
diff --git a/packages/connectivity/ios/Classes/ConnectivityPlugin.m b/packages/connectivity/ios/Classes/ConnectivityPlugin.m
index c698711..100e70b 100644
--- a/packages/connectivity/ios/Classes/ConnectivityPlugin.m
+++ b/packages/connectivity/ios/Classes/ConnectivityPlugin.m
@@ -22,6 +22,7 @@
@implementation FLTConnectivityPlugin {
FlutterEventSink _eventSink;
+ Reachability* _reachabilityForInternetConnection;
}
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
@@ -174,12 +175,16 @@
selector:@selector(onReachabilityDidChange:)
name:kReachabilityChangedNotification
object:nil];
- [[Reachability reachabilityForInternetConnection] startNotifier];
+ _reachabilityForInternetConnection = [Reachability reachabilityForInternetConnection];
+ [_reachabilityForInternetConnection startNotifier];
return nil;
}
- (FlutterError*)onCancelWithArguments:(id)arguments {
- [[Reachability reachabilityForInternetConnection] stopNotifier];
+ if (_reachabilityForInternetConnection) {
+ [_reachabilityForInternetConnection stopNotifier];
+ _reachabilityForInternetConnection = nil;
+ }
[[NSNotificationCenter defaultCenter] removeObserver:self];
_eventSink = nil;
return nil;
diff --git a/packages/connectivity/pubspec.yaml b/packages/connectivity/pubspec.yaml
index c68109d..8dce3c8 100644
--- a/packages/connectivity/pubspec.yaml
+++ b/packages/connectivity/pubspec.yaml
@@ -3,7 +3,7 @@
mobile/cellular) connectivity on Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity
-version: 0.4.5+5
+version: 0.4.5+6
flutter:
plugin: