Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -497,7 +497,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -544,7 +544,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Pod::Spec.new do |s|
s.public_header_files = 'Classes/**/*.h'

s.platform = :osx
s.osx.deployment_target = '10.11'
s.osx.deployment_target = '10.14'
end

Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.1.0

- Add ethernet as connectivity result.

NOTE: The functionality is provided by NWPathMonitor, which is available since
macOS 10.14. Therefore the minimum macOS deployment target has been changed
from 10.11 to 10.14

## 1.0.2

- Update connectivity plus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@

import Cocoa
import FlutterMacOS
import Reachability
import Network
import SystemConfiguration.CaptiveNetwork

public class ConnectivityPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
var reach: Reachability?
var eventSink: FlutterEventSink?
var pathMonitor = NWPathMonitor()

override init() {
super.init()
pathMonitor.pathUpdateHandler = pathUpdateHandler
}

public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(
Expand All @@ -39,7 +44,7 @@ public class ConnectivityPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "check":
result(statusFromReachability(reachability: Reachability.forInternetConnection()))
result(statusFromPath(path: pathMonitor.currentPath))
default:
result(FlutterMethodNotImplemented)
}
Expand All @@ -48,44 +53,36 @@ public class ConnectivityPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
/// Returns a string describing connection type
///
/// - Parameters:
/// - reachability: an instance of reachability
/// - path: an instance of NWPath
/// - Returns: connection type string
private func statusFromReachability(reachability: Reachability?) -> String {
// checks any non-WWAN connection
if reachability?.isReachableViaWiFi() ?? false {
return "wifi"
private func statusFromPath(path: NWPath) -> String {
if path.status == .satisfied {
if path.usesInterfaceType(.wifi) {
return "wifi"
} else if path.usesInterfaceType(.cellular) {
return "mobile"
} else if path.usesInterfaceType(.wiredEthernet) {
return "ethernet"
}
}

return "none"
}

public func onListen(
withArguments _: Any?,
eventSink events: @escaping FlutterEventSink
) -> FlutterError? {
reach = Reachability.forInternetConnection()
eventSink = events

NotificationCenter.default.addObserver(
self,
selector: #selector(reachabilityChanged),
name: NSNotification.Name.reachabilityChanged,
object: reach)

reach?.startNotifier()

pathMonitor.start(queue: .global(qos: .background))
return nil
}

@objc private func reachabilityChanged(notification: NSNotification) {
let reach = notification.object
let reachability = statusFromReachability(reachability: reach as? Reachability)
eventSink?(reachability)
private func pathUpdateHandler(path: NWPath) {
eventSink?(statusFromPath(path: path))
}

public func onCancel(withArguments _: Any?) -> FlutterError? {
reach?.stopNotifier()
NotificationCenter.default.removeObserver(self)
pathMonitor.cancel()
eventSink = nil
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Pod::Spec.new do |s|
s.documentation_url = 'https://pub.dev/packages/connectivity_plus'
s.source_files = 'Classes/**/*'
s.dependency 'FlutterMacOS'
s.dependency 'Reachability'

s.platform = :osx
s.osx.deployment_target = '10.11'
s.osx.deployment_target = '10.14'
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: connectivity_plus_macos
description: macOS implementation of the connectivity_plus plugin.
version: 1.0.2
version: 1.1.0
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

Expand All @@ -15,6 +15,6 @@ flutter:
pluginClass: ConnectivityPlugin

dependencies:
connectivity_plus_platform_interface: ^1.0.2
connectivity_plus_platform_interface: ^1.1.0
flutter:
sdk: flutter