Commit 634b29bf by Jaime Blasco Committed by GitHub

fix: init CBCentralManager lazely (#738)

* fix: init CBCentralManager lazely

* prepare release 9.0.0
parent deb17dc7
## 9.0.0
* iOS: Bluetooth permission dialog now appears when requested instead of when the app is initialized.
Note: Requesting Bluetooth status will also prompt the permission dialog (see issue [#591](https://github.com/Baseflow/flutter-permission-handler/issues/591)).
## 8.3.0 ## 8.3.0
* Updated Android Gradle Plugin to 4.1.0 and Gradle Wrapper to 6.7 which is inline with the current Flutter stable version (Flutter 2.5.3). * Updated Android Gradle Plugin to 4.1.0 and Gradle Wrapper to 6.7 which is inline with the current Flutter stable version (Flutter 2.5.3).
......
...@@ -132,11 +132,7 @@ ...@@ -132,11 +132,7 @@
case PermissionGroupStorage: case PermissionGroupStorage:
return [StoragePermissionStrategy new]; return [StoragePermissionStrategy new];
case PermissionGroupBluetooth: case PermissionGroupBluetooth:
#if PERMISSION_BLUETOOTH
return [[BluetoothPermissionStrategy alloc] initWithBluetoothManager];
#else
return [BluetoothPermissionStrategy new]; return [BluetoothPermissionStrategy new];
#endif
case PermissionGroupAppTrackingTransparency: case PermissionGroupAppTrackingTransparency:
return [AppTrackingTransparencyPermissionStrategy new]; return [AppTrackingTransparencyPermissionStrategy new];
case PermissionGroupCriticalAlerts: case PermissionGroupCriticalAlerts:
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#import <CoreBluetooth/CoreBluetooth.h> #import <CoreBluetooth/CoreBluetooth.h>
@interface BluetoothPermissionStrategy : NSObject <PermissionStrategy, CBCentralManagerDelegate> @interface BluetoothPermissionStrategy : NSObject <PermissionStrategy, CBCentralManagerDelegate>
-(instancetype)initWithBluetoothManager; - (void)initManagerIfNeeded;
@end @end
#else #else
......
...@@ -15,16 +15,14 @@ ...@@ -15,16 +15,14 @@
PermissionGroup _requestedPermission; PermissionGroup _requestedPermission;
} }
- (instancetype)initWithBluetoothManager { - (void)initManagerIfNeeded {
self = [super init]; if (_centralManager == nil) {
if (self) {
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
} }
return self;
} }
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission { - (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
[self initManagerIfNeeded];
if (@available(iOS 13.1, *)) { if (@available(iOS 13.1, *)) {
CBManagerAuthorization blePermission = [_centralManager authorization]; CBManagerAuthorization blePermission = [_centralManager authorization];
return [BluetoothPermissionStrategy parsePermission:blePermission]; return [BluetoothPermissionStrategy parsePermission:blePermission];
...@@ -36,6 +34,7 @@ ...@@ -36,6 +34,7 @@
} }
- (ServiceStatus)checkServiceStatus:(PermissionGroup)permission { - (ServiceStatus)checkServiceStatus:(PermissionGroup)permission {
[self initManagerIfNeeded];
if (@available(iOS 10, *)) { if (@available(iOS 10, *)) {
return [_centralManager state] == CBManagerStatePoweredOn ? ServiceStatusEnabled : ServiceStatusDisabled; return [_centralManager state] == CBManagerStatePoweredOn ? ServiceStatusEnabled : ServiceStatusDisabled;
} }
...@@ -43,6 +42,7 @@ ...@@ -43,6 +42,7 @@
} }
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler { - (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
[self initManagerIfNeeded];
PermissionStatus status = [self checkPermissionStatus:permission]; PermissionStatus status = [self checkPermissionStatus:permission];
if (status != PermissionStatusDenied) { if (status != PermissionStatusDenied) {
......
name: permission_handler name: permission_handler
description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions. description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
version: 8.3.0 version: 9.0.0
homepage: https://github.com/baseflowit/flutter-permission-handler homepage: https://github.com/baseflowit/flutter-permission-handler
flutter: flutter:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment