Commit 57bd9f52 by Jan-Derk de Vries Committed by GitHub

Enhanced bluetooth permission for iOS 13 and up (and fixed typo) (#648)

* Enhanced bluetooth permission for iOS 13 and up (and fixed typo)

* Update permission_handler/CHANGELOG.md

Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>

* Return right permission when the permission is denied

* Update pubspec.yaml

Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>
parent 7c126ea3
## 8.2.3
* iOS: Enhanced the `bluetooth` permission for iOS 13 and up, so the user gets prompted with the "bluetooth" permission dialog (see issue [#591](https://github.com/Baseflow/flutter-permission-handler/issues/591)).
## 8.2.2 ## 8.2.2
* Updated the README.md to mention setting the `compileSdkVersion` to `31`; * Updated the README.md to mention setting the `compileSdkVersion` to `31`;
...@@ -52,7 +56,7 @@ ...@@ -52,7 +56,7 @@
## 8.1.0 ## 8.1.0
* Added support for iOS 12+ Critical Alerts permission requesting. * Added support for iOS 12+ Critical Alerts permission requesting.
* NOTE: This requires applying to Apple and recieving a special entitlement from them inorder to work. See [this article](https://medium.com/@shashidharyamsani/implementing-ios-critical-alerts-7d82b4bb5026) for an explination on how to use Critical Alerts. * NOTE: This requires applying to Apple and receiving a special entitlement from them inorder to work. See [this article](https://medium.com/@shashidharyamsani/implementing-ios-critical-alerts-7d82b4bb5026) for an explination on how to use Critical Alerts.
* Added support for Android M+ Access Notification Policy permission requesting (ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS). * Added support for Android M+ Access Notification Policy permission requesting (ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS).
* Note: This opens a general page in settings, not specific to the package. * Note: This opens a general page in settings, not specific to the package.
......
...@@ -132,7 +132,11 @@ ...@@ -132,7 +132,11 @@
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:
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
#import <CoreBluetooth/CoreBluetooth.h> #import <CoreBluetooth/CoreBluetooth.h>
@interface BluetoothPermissionStrategy : NSObject <PermissionStrategy> @interface BluetoothPermissionStrategy : NSObject <PermissionStrategy, CBCentralManagerDelegate>
-(instancetype)initWithBluetoothManager;
@end @end
#else #else
......
...@@ -9,31 +9,49 @@ ...@@ -9,31 +9,49 @@
#if PERMISSION_BLUETOOTH #if PERMISSION_BLUETOOTH
@implementation BluetoothPermissionStrategy @implementation BluetoothPermissionStrategy {
CBCentralManager *_centralManager;
PermissionStatusHandler _permissionStatusHandler;
PermissionGroup _requestedPermission;
}
- (instancetype)initWithBluetoothManager {
self = [super init];
if (self) {
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
return self;
}
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission { - (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
if (@available(iOS 13.1, *)) { if (@available(iOS 13.1, *)) {
CBManagerAuthorization blePermission = [CBCentralManager authorization]; CBManagerAuthorization blePermission = [_centralManager authorization];
return [BluetoothPermissionStrategy parsePermission:blePermission]; return [BluetoothPermissionStrategy parsePermission:blePermission];
} else if (@available(iOS 13.0, *)){ } else if (@available(iOS 13.0, *)){
CBCentralManager* manager = [[CBCentralManager alloc] init]; CBManagerAuthorization blePermission = [_centralManager authorization];
CBManagerAuthorization blePermission = [manager authorization];
return [BluetoothPermissionStrategy parsePermission:blePermission]; return [BluetoothPermissionStrategy parsePermission:blePermission];
} }
return PermissionStatusGranted; return PermissionStatusGranted;
} }
- (ServiceStatus)checkServiceStatus:(PermissionGroup)permission { - (ServiceStatus)checkServiceStatus:(PermissionGroup)permission {
CBCentralManager* manager = [[CBCentralManager alloc] init];
if (@available(iOS 10, *)) { if (@available(iOS 10, *)) {
return [manager state] == CBManagerStatePoweredOn ? ServiceStatusEnabled : ServiceStatusDisabled; return [_centralManager state] == CBManagerStatePoweredOn ? ServiceStatusEnabled : ServiceStatusDisabled;
} }
return [manager state] == CBCentralManagerStatePoweredOn ? ServiceStatusEnabled : ServiceStatusDisabled; return [_centralManager state] == CBCentralManagerStatePoweredOn ? ServiceStatusEnabled : ServiceStatusDisabled;
} }
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler { - (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
completionHandler([self checkPermissionStatus:permission]); PermissionStatus status = [self checkPermissionStatus:permission];
if (status != PermissionStatusDenied) {
completionHandler(status);
return;
}
_permissionStatusHandler = completionHandler;
_requestedPermission = permission;
} }
+ (PermissionStatus)parsePermission:(CBManagerAuthorization)bluetoothPermission API_AVAILABLE(ios(13)){ + (PermissionStatus)parsePermission:(CBManagerAuthorization)bluetoothPermission API_AVAILABLE(ios(13)){
...@@ -43,11 +61,17 @@ ...@@ -43,11 +61,17 @@
case CBManagerAuthorizationRestricted: case CBManagerAuthorizationRestricted:
return PermissionStatusRestricted; return PermissionStatusRestricted;
case CBManagerAuthorizationDenied: case CBManagerAuthorizationDenied:
return PermissionStatusDenied; return PermissionStatusPermanentlyDenied;
case CBManagerAuthorizationAllowedAlways: case CBManagerAuthorizationAllowedAlways:
return PermissionStatusGranted; return PermissionStatusGranted;
} }
} }
- (void)centralManagerDidUpdateState:(nonnull CBCentralManager *)centralManager {
PermissionStatus permissionStatus = [self checkPermissionStatus:_requestedPermission];
_permissionStatusHandler(permissionStatus);
}
@end @end
#else #else
......
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.2.2 version: 8.2.3
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