Skip to content

Commit

Permalink
Ios : try reconnect on unexpected disconnection (fixed by EB-Plum)
Browse files Browse the repository at this point in the history
  • Loading branch information
officelioneight committed Jan 31, 2022
1 parent e9ee49b commit c7bbdf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.1.0

* Android: Add missing break in switch, which causes exceptions
* Ios : try reconnect on unexpected disconnection (fixed by EB-Plum)
* Android: Add missing break in switch, which causes exceptions (fixed by russelltg)
* Android: Enforcing maxSdkVersion on the ACCESS_FINE_LOCATION permission will create issues for Android 12 devices that use location for purposes other than Bluetooth (such as using packages that actually need location). (fixed by rickcasson)

## 1.0.0
Expand Down
19 changes: 16 additions & 3 deletions ios/Classes/FlutterBluePlusPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
message:@"Peripheral not found"
details:nil];
}
if( [peripheral state] == CBPeripheralStateDisconnected){
[_centralManager connectPeripheral:peripheral options:nil];
}
// TODO: Implement Connect options (#36)
[_centralManager connectPeripheral:peripheral options:nil];
result(nil);
} @catch(FlutterError *e) {
result(e);
Expand Down Expand Up @@ -393,8 +395,19 @@ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPerip

- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
NSLog(@"didDisconnectPeripheral");
// Unregister self as delegate for peripheral, not working #42
peripheral.delegate = nil;
// if user disconnect manually, error code should be 0
if( [error code] != 0 ){
// unexpected disconnection -> try reconnect
@try {
NSLog(@"didDisconnectPeripheral:trying reconnect");
[central connectPeripheral:peripheral options:nil];
} @catch(FlutterError *e) {
}
}else{
NSLog(@"didDisconnectPeripheral:user disconnected");
// Unregister self as delegate for peripheral, not working #42
peripheral.delegate = nil;
}

// Send connection state
[_channel invokeMethod:@"DeviceState" arguments:[self toFlutterData:[self toDeviceStateProto:peripheral state:peripheral.state]]];
Expand Down

0 comments on commit c7bbdf0

Please sign in to comment.