From 0f2ed3a2ca4ef0900ed1f8663e609c7ab8710d61 Mon Sep 17 00:00:00 2001 From: Vadim Albul Date: Thu, 7 May 2020 15:53:07 +0300 Subject: [PATCH 1/4] - add notify options for connecting to the device --- REFERENCE.md | 7 +++++-- example/ios/Flutter/.last_build_id | 1 + example/ios/Runner.xcodeproj/project.pbxproj | 21 +++++-------------- .../device_details/device_details_bloc.dart | 2 +- ios/Classes/Constants/ArgumentKey.h | 4 ++++ ios/Classes/Constants/ArgumentKey.m | 4 ++++ ios/Classes/FlutterBleLibPlugin.m | 8 ++++--- lib/peripheral.dart | 11 ++++++++-- lib/src/_constants.dart | 4 ++++ lib/src/_managers_for_classes.dart | 3 +++ lib/src/bridge/device_connection_mixin.dart | 16 +++++++++++--- lib/src/internal_ble_manager.dart | 5 ++++- 12 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 example/ios/Flutter/.last_build_id diff --git a/REFERENCE.md b/REFERENCE.md index e6e9429a..e9b14bd0 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -142,9 +142,12 @@ All of the following methods belong to Peripheral instance. ```dart Future connect( {bool isAutoConnect = false, - int requestMtu, + int requestMtu = NO_MTU_NEGOTIATION, bool refreshGatt = false, - Duration timeout}); + Duration timeout, + bool isNotifyOnConnection = false, + bool isNotifyOnDisconnection = false, + bool isNotifyOnNotification = false}); ``` Attempts to connect to the peripheral. diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id new file mode 100644 index 00000000..8c8175e0 --- /dev/null +++ b/example/ios/Flutter/.last_build_id @@ -0,0 +1 @@ +4f11915e6f18e69d752ebc20c26f62c7 \ No newline at end of file diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index f32ba7b6..b7cf5f69 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -10,11 +10,7 @@ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 1F98025F8F407F461CB357DF /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E99B52135973B0C19BFDEF7 /* Pods_Runner.framework */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 81E1240A2334F85D005D9563 /* SwiftBridging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81E124092334F85D005D9563 /* SwiftBridging.swift */; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; @@ -30,8 +26,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -45,7 +39,6 @@ 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 1AB7F698716680F75BACA8D9 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -54,7 +47,6 @@ 96C714B17D5919D3696FE535 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -68,8 +60,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 1F98025F8F407F461CB357DF /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -80,9 +70,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -189,6 +177,7 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = 37APR7NT5C; LastSwiftMigration = 1030; ProvisioningStyle = Automatic; SystemCapabilities = { @@ -260,7 +249,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin\n"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -393,7 +382,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 37APR7NT5C; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -529,7 +518,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 37APR7NT5C; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -560,7 +549,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 37APR7NT5C; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", diff --git a/example/lib/device_details/device_details_bloc.dart b/example/lib/device_details/device_details_bloc.dart index 693de732..341ced19 100644 --- a/example/lib/device_details/device_details_bloc.dart +++ b/example/lib/device_details/device_details_bloc.dart @@ -224,7 +224,7 @@ class DeviceDetailsBloc { try { log("Connecting to ${peripheral.name}"); - await peripheral.connect(); + await peripheral.connect(isAutoConnect: true, isNotifyOnConnection: true, isNotifyOnDisconnection: true, isNotifyOnNotification: true,); log("Connected!"); } on BleError catch (e) { logError(e.toString()); diff --git a/ios/Classes/Constants/ArgumentKey.h b/ios/Classes/Constants/ArgumentKey.h index 56981d17..a34bcb87 100644 --- a/ios/Classes/Constants/ArgumentKey.h +++ b/ios/Classes/Constants/ArgumentKey.h @@ -22,6 +22,10 @@ extern NSString * const ARGUMENT_KEY_CHARACTERISTIC_IDENTIFIER; extern NSString * const ARGUMENT_KEY_VALUE; extern NSString * const ARGUMENT_KEY_WITH_RESPONSE; +extern NSString * const ARGUMENT_KEY_NOTIFY_ON_NOTIFICATION; +extern NSString * const ARGUMENT_KEY_NOTIFY_ON_DISCONNECTION; +extern NSString * const ARGUMENT_KEY_NOTIFY_ON_CONNECTION; + extern NSString * const ARGUMENT_KEY_DESCRIPTOR_UUID; extern NSString * const ARGUMENT_KEY_DESCRIPTOR_IDENTIFIER; diff --git a/ios/Classes/Constants/ArgumentKey.m b/ios/Classes/Constants/ArgumentKey.m index 590a4df8..d56cdaf7 100644 --- a/ios/Classes/Constants/ArgumentKey.m +++ b/ios/Classes/Constants/ArgumentKey.m @@ -13,6 +13,10 @@ NSString * const ARGUMENT_KEY_TIMEOUT_MILLIS = @"timeoutMillis"; NSString * const ARGUMENT_KEY_EMIT_CURRENT_VALUE = @"emitCurrentValue"; +NSString * const ARGUMENT_KEY_NOTIFY_ON_NOTIFICATION = @"notifyOnNotification"; +NSString * const ARGUMENT_KEY_NOTIFY_ON_DISCONNECTION = @"notifyOnDisconnection"; +NSString * const ARGUMENT_KEY_NOTIFY_ON_CONNECTION = @"notifyOnConnection"; + NSString * const ARGUMENT_KEY_LOG_LEVEL = @"logLevel"; NSString * const ARGUMENT_KEY_SERVICE_UUID = @"serviceUuid"; diff --git a/ios/Classes/FlutterBleLibPlugin.m b/ios/Classes/FlutterBleLibPlugin.m index 07e26441..b8e51e8c 100644 --- a/ios/Classes/FlutterBleLibPlugin.m +++ b/ios/Classes/FlutterBleLibPlugin.m @@ -209,11 +209,13 @@ - (void)stopDeviceScan:(FlutterResult)result { // MARK: - MBA Methods - Connection - (void)connectToDevice:(FlutterMethodCall *)call result:(FlutterResult)result { - NSArray* expectedArguments = [NSArray arrayWithObjects:ARGUMENT_KEY_TIMEOUT_MILLIS, nil]; + NSArray* expectedArguments = [NSArray arrayWithObjects:ARGUMENT_KEY_TIMEOUT_MILLIS, ARGUMENT_KEY_NOTIFY_ON_NOTIFICATION, ARGUMENT_KEY_NOTIFY_ON_DISCONNECTION, ARGUMENT_KEY_NOTIFY_ON_CONNECTION, nil]; + NSDictionary* options = [ArgumentHandler dictionaryOrNil:expectedArguments in:call.arguments]; + [_adapter connectToDevice:call.arguments[ARGUMENT_KEY_DEVICE_IDENTIFIER] - options:[ArgumentHandler dictionaryOrNil:expectedArguments in:call.arguments] + options:options resolve:result - reject:[self rejectForFlutterResult:result]]; + reject:[self rejectForFlutterResult:result]]; } - (void)cancelDeviceConnection:(FlutterMethodCall *)call result:(FlutterResult)result { diff --git a/lib/peripheral.dart b/lib/peripheral.dart index c8298878..741bcb6c 100644 --- a/lib/peripheral.dart +++ b/lib/peripheral.dart @@ -52,12 +52,19 @@ class Peripheral { {bool isAutoConnect = false, int requestMtu = NO_MTU_NEGOTIATION, bool refreshGatt = false, - Duration timeout}) => + Duration timeout, + bool isNotifyOnConnection = false, + bool isNotifyOnDisconnection = false, + bool isNotifyOnNotification = false}) => _manager.connectToPeripheral(identifier, isAutoConnect: isAutoConnect, requestMtu: requestMtu, refreshGatt: refreshGatt, - timeout: timeout); + timeout: timeout, + isNotifyOnConnection: isNotifyOnNotification, + isNotifyOnDisconnection: isNotifyOnDisconnection, + isNotifyOnNotification: isNotifyOnNotification + ); /// Returns a stream of [PeripheralConnectionState]. /// diff --git a/lib/src/_constants.dart b/lib/src/_constants.dart index 18e53266..bfe8fbf9 100644 --- a/lib/src/_constants.dart +++ b/lib/src/_constants.dart @@ -115,6 +115,10 @@ abstract class ArgumentName { static const String mtu = "mtu"; static const String deviceIdentifiers = "deviceIdentifiers"; + + static const String notifyOnNotification = "notifyOnNotification"; + static const String notifyOnDisconnection = "notifyOnDisconnection"; + static const String notifyOnConnection = "notifyOnConnection"; } abstract class NativeConnectionState { diff --git a/lib/src/_managers_for_classes.dart b/lib/src/_managers_for_classes.dart index 69a92814..907df968 100644 --- a/lib/src/_managers_for_classes.dart +++ b/lib/src/_managers_for_classes.dart @@ -11,6 +11,9 @@ abstract class ManagerForPeripheral { int requestMtu, bool refreshGatt, Duration timeout, + bool isNotifyOnConnection, + bool isNotifyOnDisconnection, + bool isNotifyOnNotification, }); Future isPeripheralConnected(String peripheralIdentifier); diff --git a/lib/src/bridge/device_connection_mixin.dart b/lib/src/bridge/device_connection_mixin.dart index 55aa17b9..b59bd5bb 100644 --- a/lib/src/bridge/device_connection_mixin.dart +++ b/lib/src/bridge/device_connection_mixin.dart @@ -5,15 +5,25 @@ mixin DeviceConnectionMixin on FlutterBLE { const EventChannel(ChannelName.connectionStateChangeEvents) .receiveBroadcastStream(); - Future connectToPeripheral(String deviceIdentifier, bool isAutoConnect, - int requestMtu, bool refreshGatt, Duration timeout) async { + Future connectToPeripheral(String deviceIdentifier, + bool isAutoConnect, + int requestMtu, + bool refreshGatt, + Duration timeout, + bool isNotifyOnConnection, + bool isNotifyOnDisconnection, + bool isNotifyOnNotification, + ) async { return await _methodChannel .invokeMethod(MethodName.connectToDevice, { ArgumentName.deviceIdentifier: deviceIdentifier, ArgumentName.isAutoConnect: isAutoConnect, ArgumentName.requestMtu: requestMtu, ArgumentName.refreshGatt: refreshGatt, - ArgumentName.timeoutMillis: timeout?.inMilliseconds + ArgumentName.timeoutMillis: timeout?.inMilliseconds, + ArgumentName.notifyOnConnection: isNotifyOnConnection, + ArgumentName.notifyOnDisconnection: isNotifyOnDisconnection, + ArgumentName.notifyOnNotification: isNotifyOnNotification }).catchError((errorJson) => Future.error(BleError.fromJson(jsonDecode(errorJson.details)))); } diff --git a/lib/src/internal_ble_manager.dart b/lib/src/internal_ble_manager.dart index 5234e89c..a0de9540 100644 --- a/lib/src/internal_ble_manager.dart +++ b/lib/src/internal_ble_manager.dart @@ -69,9 +69,12 @@ class InternalBleManager int requestMtu, bool refreshGatt, Duration timeout, + bool isNotifyOnConnection, + bool isNotifyOnDisconnection, + bool isNotifyOnNotification, }) async => _bleLib.connectToPeripheral( - identifier, isAutoConnect, requestMtu, refreshGatt, timeout); + identifier, isAutoConnect, requestMtu, refreshGatt, timeout, isNotifyOnConnection, isNotifyOnDisconnection, isNotifyOnNotification); @override Stream observePeripheralConnectionState( From 5766eb6aa319a14cf411719b4c4e8a1f35cd3693 Mon Sep 17 00:00:00 2001 From: Vadim Albul Date: Thu, 7 May 2020 16:22:20 +0300 Subject: [PATCH 2/4] -fix code --- example/ios/Runner.xcodeproj/project.pbxproj | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index b7cf5f69..ef2dd3e5 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -177,7 +177,6 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = 37APR7NT5C; LastSwiftMigration = 1030; ProvisioningStyle = Automatic; SystemCapabilities = { @@ -382,7 +381,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 37APR7NT5C; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -518,7 +517,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 37APR7NT5C; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -549,7 +548,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 37APR7NT5C; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", From 19bac06600bc512ef6df0dec6622355adb1ab0eb Mon Sep 17 00:00:00 2001 From: Vadim Albul Date: Thu, 28 May 2020 11:52:29 +0300 Subject: [PATCH 3/4] - add new params --- example/ios/Flutter/.last_build_id | 2 +- example/ios/Podfile | 1 + example/ios/Podfile.lock | 21 ++++++++++++-------- example/ios/Runner.xcodeproj/project.pbxproj | 3 --- ios/Classes/Constants/ArgumentKey.m | 3 +++ lib/src/_constants.dart | 3 +++ 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id index 8c8175e0..27a462e8 100644 --- a/example/ios/Flutter/.last_build_id +++ b/example/ios/Flutter/.last_build_id @@ -1 +1 @@ -4f11915e6f18e69d752ebc20c26f62c7 \ No newline at end of file +0c043f712767a79a690d42e9fd9f6d89 \ No newline at end of file diff --git a/example/ios/Podfile b/example/ios/Podfile index b30a428b..7c73f783 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -62,6 +62,7 @@ target 'Runner' do end # Keep pod path relative so it can be checked into Podfile.lock. + pod 'MultiplatformBleAdapter', :git => 'https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git', :branch => 'feature/connect-options' pod 'Flutter', :path => 'Flutter' # Plugin Pods diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index a6a5adb4..98c1910b 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -4,32 +4,37 @@ PODS: - Flutter - MultiplatformBleAdapter (= 0.1.5) - MultiplatformBleAdapter (0.1.5) - - "permission_handler (4.2.0+hotfix.3)": + - "permission_handler (4.4.0+hotfix.4)": - Flutter DEPENDENCIES: - Flutter (from `Flutter`) - flutter_ble_lib (from `.symlinks/plugins/flutter_ble_lib/ios`) + - MultiplatformBleAdapter (from `https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git`, branch `feature/connect-options`) - permission_handler (from `.symlinks/plugins/permission_handler/ios`) -SPEC REPOS: - trunk: - - MultiplatformBleAdapter - EXTERNAL SOURCES: Flutter: :path: Flutter flutter_ble_lib: :path: ".symlinks/plugins/flutter_ble_lib/ios" + MultiplatformBleAdapter: + :branch: feature/connect-options + :git: https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git permission_handler: :path: ".symlinks/plugins/permission_handler/ios" +CHECKOUT OPTIONS: + MultiplatformBleAdapter: + :commit: db9cb2ff5ce6731cf017135ff899c287b4bec222 + :git: https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git + SPEC CHECKSUMS: Flutter: 0e3d915762c693b495b44d77113d4970485de6ec flutter_ble_lib: 20e79f0b1d78d921d9ed68ab4451e190029bc3d9 MultiplatformBleAdapter: 3c4391d428382738a47662ae1f665a29ce78ff39 - permission_handler: 40520ab8ad1bb78a282b832464e995ec87f77ec6 + permission_handler: 8278954f2382902f63f00dd8828769c0bd6d511b -PODFILE CHECKSUM: 1b66dae606f75376c5f2135a8290850eeb09ae83 +PODFILE CHECKSUM: dcf3fe9bdbec5b17c2addc228de1c35b86774192 -COCOAPODS: 1.8.4 +COCOAPODS: 1.9.1 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index ef2dd3e5..dec8f0df 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -324,7 +324,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -404,7 +403,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -460,7 +458,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; diff --git a/ios/Classes/Constants/ArgumentKey.m b/ios/Classes/Constants/ArgumentKey.m index d56cdaf7..e4615404 100644 --- a/ios/Classes/Constants/ArgumentKey.m +++ b/ios/Classes/Constants/ArgumentKey.m @@ -16,6 +16,9 @@ NSString * const ARGUMENT_KEY_NOTIFY_ON_NOTIFICATION = @"notifyOnNotification"; NSString * const ARGUMENT_KEY_NOTIFY_ON_DISCONNECTION = @"notifyOnDisconnection"; NSString * const ARGUMENT_KEY_NOTIFY_ON_CONNECTION = @"notifyOnConnection"; +NSString * const ARGUMENT_KEY_ENABLE_TRANSPORT_BRIDGING = @"enableTransportBridging"; +NSString * const ARGUMENT_KEY_REQUIRES_ANCS = @"requiresANCS"; +NSString * const ARGUMENT_KEY_START_DELAY = @"startDelay"; NSString * const ARGUMENT_KEY_LOG_LEVEL = @"logLevel"; diff --git a/lib/src/_constants.dart b/lib/src/_constants.dart index bfe8fbf9..fd5aae0a 100644 --- a/lib/src/_constants.dart +++ b/lib/src/_constants.dart @@ -119,6 +119,9 @@ abstract class ArgumentName { static const String notifyOnNotification = "notifyOnNotification"; static const String notifyOnDisconnection = "notifyOnDisconnection"; static const String notifyOnConnection = "notifyOnConnection"; + static const String enableTransportBridging = "enableTransportBridging"; + static const String requiresANCS = "requiresANCS"; + static const String startDelay = "startDelay"; } abstract class NativeConnectionState { From 7304767859c771ba4a8f8f67f5bef06437d90676 Mon Sep 17 00:00:00 2001 From: Vadim Albul Date: Fri, 12 Jun 2020 10:21:54 +0300 Subject: [PATCH 4/4] - added new parameters for connecting to peripheral --- example/ios/Flutter/.last_build_id | 2 +- example/ios/Podfile | 3 +-- example/ios/Podfile.lock | 15 ++++------- lib/peripheral.dart | 28 ++++++++++++++++++--- lib/src/_managers_for_classes.dart | 3 +++ lib/src/bridge/device_connection_mixin.dart | 12 ++++++--- lib/src/internal_ble_manager.dart | 17 ++++++++++--- 7 files changed, 58 insertions(+), 22 deletions(-) diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id index 27a462e8..d7b781ad 100644 --- a/example/ios/Flutter/.last_build_id +++ b/example/ios/Flutter/.last_build_id @@ -1 +1 @@ -0c043f712767a79a690d42e9fd9f6d89 \ No newline at end of file +7fc9c9500a628906af1c5baf9385035d \ No newline at end of file diff --git a/example/ios/Podfile b/example/ios/Podfile index 7c73f783..8e0967df 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -62,8 +62,7 @@ target 'Runner' do end # Keep pod path relative so it can be checked into Podfile.lock. - pod 'MultiplatformBleAdapter', :git => 'https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git', :branch => 'feature/connect-options' - pod 'Flutter', :path => 'Flutter' + pod 'Flutter', :path => 'Flutter' # Plugin Pods diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 98c1910b..79fd3818 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -10,31 +10,26 @@ PODS: DEPENDENCIES: - Flutter (from `Flutter`) - flutter_ble_lib (from `.symlinks/plugins/flutter_ble_lib/ios`) - - MultiplatformBleAdapter (from `https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git`, branch `feature/connect-options`) - permission_handler (from `.symlinks/plugins/permission_handler/ios`) +SPEC REPOS: + trunk: + - MultiplatformBleAdapter + EXTERNAL SOURCES: Flutter: :path: Flutter flutter_ble_lib: :path: ".symlinks/plugins/flutter_ble_lib/ios" - MultiplatformBleAdapter: - :branch: feature/connect-options - :git: https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git permission_handler: :path: ".symlinks/plugins/permission_handler/ios" -CHECKOUT OPTIONS: - MultiplatformBleAdapter: - :commit: db9cb2ff5ce6731cf017135ff899c287b4bec222 - :git: https://github.com/devVadimAlbul/MultiPlatformBleAdapter.git - SPEC CHECKSUMS: Flutter: 0e3d915762c693b495b44d77113d4970485de6ec flutter_ble_lib: 20e79f0b1d78d921d9ed68ab4451e190029bc3d9 MultiplatformBleAdapter: 3c4391d428382738a47662ae1f665a29ce78ff39 permission_handler: 8278954f2382902f63f00dd8828769c0bd6d511b -PODFILE CHECKSUM: dcf3fe9bdbec5b17c2addc228de1c35b86774192 +PODFILE CHECKSUM: 84720d6720b1cd5ac49da90536aac58b9f839038 COCOAPODS: 1.9.1 diff --git a/lib/peripheral.dart b/lib/peripheral.dart index 741bcb6c..807295dd 100644 --- a/lib/peripheral.dart +++ b/lib/peripheral.dart @@ -48,6 +48,22 @@ class Peripheral { /// is established right after timeout event, peripheral will be disconnected /// immediately. Timeout may happen earlier then specified due to OS /// specific behavior. + /// + /// Optional params [isNotifyOnConnection], [isNotifyOnDisconnection], [isNotifyOnNotification] + /// is used for automatically notify app when this device connected/disconnected + /// or send notification about change its state (IOS only) + /// is used in background mode + /// + /// Optional [enableTransportBridging] is indicating that the system will bring up classic + /// transport profiles when low energy transport for peripheral is connected (iOS 13.0 or more only) + /// + /// Optional [isRequiresANCS] is indicating that the ANCS (Apple Notification Center Service) + /// is required for the peripheral is connected. (iOS 13.0 or more only) + /// + /// Optional [startDelay] is indicating the number of seconds + /// for the system to wait before starting a connection. (iOS only) + /// + /// Future connect( {bool isAutoConnect = false, int requestMtu = NO_MTU_NEGOTIATION, @@ -55,15 +71,21 @@ class Peripheral { Duration timeout, bool isNotifyOnConnection = false, bool isNotifyOnDisconnection = false, - bool isNotifyOnNotification = false}) => + bool isNotifyOnNotification = false, + bool enableTransportBridging = false, + bool isRequiresANCS = false, + Duration startDelay}) => _manager.connectToPeripheral(identifier, isAutoConnect: isAutoConnect, requestMtu: requestMtu, refreshGatt: refreshGatt, timeout: timeout, - isNotifyOnConnection: isNotifyOnNotification, + isNotifyOnConnection: isNotifyOnConnection, isNotifyOnDisconnection: isNotifyOnDisconnection, - isNotifyOnNotification: isNotifyOnNotification + isNotifyOnNotification: isNotifyOnNotification, + enableTransportBridging: enableTransportBridging, + isRequiresANCS: isRequiresANCS, + startDelay: startDelay ); /// Returns a stream of [PeripheralConnectionState]. diff --git a/lib/src/_managers_for_classes.dart b/lib/src/_managers_for_classes.dart index 907df968..4eb695ae 100644 --- a/lib/src/_managers_for_classes.dart +++ b/lib/src/_managers_for_classes.dart @@ -14,6 +14,9 @@ abstract class ManagerForPeripheral { bool isNotifyOnConnection, bool isNotifyOnDisconnection, bool isNotifyOnNotification, + bool enableTransportBridging, + bool isRequiresANCS, + Duration startDelay }); Future isPeripheralConnected(String peripheralIdentifier); diff --git a/lib/src/bridge/device_connection_mixin.dart b/lib/src/bridge/device_connection_mixin.dart index b59bd5bb..2398d80d 100644 --- a/lib/src/bridge/device_connection_mixin.dart +++ b/lib/src/bridge/device_connection_mixin.dart @@ -5,7 +5,7 @@ mixin DeviceConnectionMixin on FlutterBLE { const EventChannel(ChannelName.connectionStateChangeEvents) .receiveBroadcastStream(); - Future connectToPeripheral(String deviceIdentifier, + Future connectToPeripheral({String deviceIdentifier, bool isAutoConnect, int requestMtu, bool refreshGatt, @@ -13,7 +13,10 @@ mixin DeviceConnectionMixin on FlutterBLE { bool isNotifyOnConnection, bool isNotifyOnDisconnection, bool isNotifyOnNotification, - ) async { + bool enableTransportBridging, + bool isRequiresANCS, + Duration startDelay +}) async { return await _methodChannel .invokeMethod(MethodName.connectToDevice, { ArgumentName.deviceIdentifier: deviceIdentifier, @@ -23,7 +26,10 @@ mixin DeviceConnectionMixin on FlutterBLE { ArgumentName.timeoutMillis: timeout?.inMilliseconds, ArgumentName.notifyOnConnection: isNotifyOnConnection, ArgumentName.notifyOnDisconnection: isNotifyOnDisconnection, - ArgumentName.notifyOnNotification: isNotifyOnNotification + ArgumentName.notifyOnNotification: isNotifyOnNotification, + ArgumentName.enableTransportBridging: enableTransportBridging, + ArgumentName.requiresANCS: isRequiresANCS, + ArgumentName.startDelay: startDelay?.inSeconds }).catchError((errorJson) => Future.error(BleError.fromJson(jsonDecode(errorJson.details)))); } diff --git a/lib/src/internal_ble_manager.dart b/lib/src/internal_ble_manager.dart index a0de9540..1bea4fe7 100644 --- a/lib/src/internal_ble_manager.dart +++ b/lib/src/internal_ble_manager.dart @@ -72,9 +72,20 @@ class InternalBleManager bool isNotifyOnConnection, bool isNotifyOnDisconnection, bool isNotifyOnNotification, - }) async => - _bleLib.connectToPeripheral( - identifier, isAutoConnect, requestMtu, refreshGatt, timeout, isNotifyOnConnection, isNotifyOnDisconnection, isNotifyOnNotification); + bool enableTransportBridging, + bool isRequiresANCS, + Duration startDelay + }) async => _bleLib.connectToPeripheral( + deviceIdentifier: identifier, + isAutoConnect: isAutoConnect, + requestMtu: requestMtu, + refreshGatt: refreshGatt, + isNotifyOnConnection: isNotifyOnConnection, + isNotifyOnDisconnection: isNotifyOnDisconnection, + isNotifyOnNotification: isNotifyOnNotification, + isRequiresANCS: isRequiresANCS, + startDelay: startDelay + ); @override Stream observePeripheralConnectionState(