Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ All of the following methods belong to Peripheral instance.
```dart
Future<void> 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.

Expand Down
1 change: 1 addition & 0 deletions example/ios/Flutter/.last_build_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0c043f712767a79a690d42e9fd9f6d89
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be ignored, I think?

1 change: 1 addition & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have to be reverted before merging - marking to not forget

pod 'Flutter', :path => 'Flutter'

# Plugin Pods
Expand Down
21 changes: 13 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 1 addition & 16 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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;
Expand All @@ -45,7 +39,6 @@
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
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 = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand All @@ -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 = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
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 = "<group>"; };
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand All @@ -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;
Expand All @@ -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 */,
Expand Down Expand Up @@ -260,7 +248,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;
Expand Down Expand Up @@ -336,7 +324,6 @@
/* Begin XCBuildConfiguration section */
249021D3217E4FDB00AE95B9 /* Profile */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -416,7 +403,6 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -472,7 +458,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down
2 changes: 1 addition & 1 deletion example/lib/device_details/device_details_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/Constants/ArgumentKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions ios/Classes/Constants/ArgumentKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
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_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";

NSString * const ARGUMENT_KEY_SERVICE_UUID = @"serviceUuid";
Expand Down
8 changes: 5 additions & 3 deletions ios/Classes/FlutterBleLibPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions lib/peripheral.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}) =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add dart docs for the new arguments?

_manager.connectToPeripheral(identifier,
isAutoConnect: isAutoConnect,
requestMtu: requestMtu,
refreshGatt: refreshGatt,
timeout: timeout);
timeout: timeout,
isNotifyOnConnection: isNotifyOnNotification,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isNotifyOnConnection: isNotifyOnNotification,
isNotifyOnConnection: isNotifyOnConnection,

isNotifyOnDisconnection: isNotifyOnDisconnection,
isNotifyOnNotification: isNotifyOnNotification
);

/// Returns a stream of [PeripheralConnectionState].
///
Expand Down
7 changes: 7 additions & 0 deletions lib/src/_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ 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";
static const String enableTransportBridging = "enableTransportBridging";
static const String requiresANCS = "requiresANCS";
static const String startDelay = "startDelay";
}

abstract class NativeConnectionState {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/_managers_for_classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ abstract class ManagerForPeripheral {
int requestMtu,
bool refreshGatt,
Duration timeout,
bool isNotifyOnConnection,
bool isNotifyOnDisconnection,
bool isNotifyOnNotification,
});

Future<bool> isPeripheralConnected(String peripheralIdentifier);
Expand Down
16 changes: 13 additions & 3 deletions lib/src/bridge/device_connection_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ mixin DeviceConnectionMixin on FlutterBLE {
const EventChannel(ChannelName.connectionStateChangeEvents)
.receiveBroadcastStream();

Future<void> connectToPeripheral(String deviceIdentifier, bool isAutoConnect,
int requestMtu, bool refreshGatt, Duration timeout) async {
Future<void> connectToPeripheral(String deviceIdentifier,
bool isAutoConnect,
int requestMtu,
bool refreshGatt,
Duration timeout,
bool isNotifyOnConnection,
bool isNotifyOnDisconnection,
bool isNotifyOnNotification,
) async {
return await _methodChannel
.invokeMethod(MethodName.connectToDevice, <String, dynamic>{
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))));
}
Expand Down
5 changes: 4 additions & 1 deletion lib/src/internal_ble_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeripheralConnectionState> observePeripheralConnectionState(
Expand Down