Skip to content

Commit

Permalink
feat(connectivity): shared codebase for apple products
Browse files Browse the repository at this point in the history
Signed-off-by: George Kutsurua <[email protected]>
  • Loading branch information
suquant committed Feb 24, 2024
1 parent d527366 commit 3c28de7
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if TARGET_OS_IOS
#import <Flutter/Flutter.h>
#elif TARGET_OS_OSX
#import <FlutterMacOS/FlutterMacOS.h>
#endif

@interface ConnectivityPlugin : NSObject <FlutterPlugin>
@end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "ConnectivityPlusPlugin.h"
#import "ConnectivityPlugin.h"
#if __has_include(<connectivity_plus/connectivity_plus-Swift.h>)
#import <connectivity_plus/connectivity_plus-Swift.h>
#else
Expand All @@ -8,8 +8,8 @@
#import "connectivity_plus-Swift.h"
#endif

@implementation ConnectivityPlusPlugin
@implementation ConnectivityPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
[SwiftConnectivityPlusPlugin registerWithRegistrar:registrar];
[SwiftConnectivityPlugin registerWithRegistrar:registrar];
}
@end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Network

@available(iOS 12, *)
@available(iOS 12, macOS 10.14, *)
public class PathMonitorConnectivityProvider: NSObject, ConnectivityProvider {

private let queue = DispatchQueue.global(qos: .background)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
// Use of this source is governed by a BSD-style license that can
// be found in the LICENSE file.

#if os(iOS)
import Flutter
#elseif os(macOS)
import Cocoa
import FlutterMacOS
#endif

public class SwiftConnectivityPlusPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
public class SwiftConnectivityPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
private let connectivityProvider: ConnectivityProvider
private var eventSink: FlutterEventSink?

Expand All @@ -15,22 +20,28 @@ public class SwiftConnectivityPlusPlugin: NSObject, FlutterPlugin, FlutterStream
}

public static func register(with registrar: FlutterPluginRegistrar) {
#if os(iOS)
let binaryMessenger = registrar.messenger()
#elseif os(macOS)
let binaryMessenger = registrar.messenger
#endif

let channel = FlutterMethodChannel(
name: "dev.fluttercommunity.plus/connectivity",
binaryMessenger: registrar.messenger())
binaryMessenger: binaryMessenger)

let streamChannel = FlutterEventChannel(
name: "dev.fluttercommunity.plus/connectivity_status",
binaryMessenger: registrar.messenger())
binaryMessenger: binaryMessenger)

let connectivityProvider: ConnectivityProvider
if #available(iOS 12, *) {
if #available(iOS 12, macOS 10.14, *) {
connectivityProvider = PathMonitorConnectivityProvider()
} else {
connectivityProvider = ReachabilityConnectivityProvider()
}

let instance = SwiftConnectivityPlusPlugin(connectivityProvider: connectivityProvider)
let instance = SwiftConnectivityPlugin(connectivityProvider: connectivityProvider)
streamChannel.setStreamHandler(instance)

registrar.addMethodCallDelegate(instance, channel: channel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ Downloaded by pub (not CocoaPods).
s.author = { 'Flutter Community Team' => '[email protected]' }
s.source = { :http => 'https://github.com/fluttercommunity/plus_plugins/tree/main/packages/connectivity_plus' }
s.documentation_url = 'https://pub.dev/packages/connectivity_plus'
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.source_files = [
'Classes/**/*'
]
s.public_header_files = [
'Classes/**/*.h'
]
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.dependency 'ReachabilitySwift'
s.platform = :ios, '12.0'
s.platform = {
:ios => '12.0',
:osx => '10.14'
}
s.ios.deployment_target = '12.0'
s.osx.deployment_target = '10.14'
s.swift_version = '5.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.resource_bundles = {'connectivity_plus_privacy' => ['PrivacyInfo.xcprivacy']}
s.ios.resource_bundles = {'connectivity_plus_privacy' => ['PrivacyInfo.xcprivacy']}
end

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3c28de7

Please sign in to comment.