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
* Updated the README.md to mention setting the `compileSdkVersion` to `31`;
......@@ -52,7 +56,7 @@
## 8.1.0
* 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).
* Note: This opens a general page in settings, not specific to the package.
......
......@@ -132,7 +132,11 @@
case PermissionGroupStorage:
return [StoragePermissionStrategy new];
case PermissionGroupBluetooth:
#if PERMISSION_BLUETOOTH
return [[BluetoothPermissionStrategy alloc] initWithBluetoothManager];
#else
return [BluetoothPermissionStrategy new];
#endif
case PermissionGroupAppTrackingTransparency:
return [AppTrackingTransparencyPermissionStrategy new];
case PermissionGroupCriticalAlerts:
......
......@@ -12,7 +12,8 @@
#import <CoreBluetooth/CoreBluetooth.h>
@interface BluetoothPermissionStrategy : NSObject <PermissionStrategy>
@interface BluetoothPermissionStrategy : NSObject <PermissionStrategy, CBCentralManagerDelegate>
-(instancetype)initWithBluetoothManager;
@end
#else
......
......@@ -9,31 +9,49 @@
#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 {
if (@available(iOS 13.1, *)) {
CBManagerAuthorization blePermission = [CBCentralManager authorization];
CBManagerAuthorization blePermission = [_centralManager authorization];
return [BluetoothPermissionStrategy parsePermission:blePermission];
} else if (@available(iOS 13.0, *)){
CBCentralManager* manager = [[CBCentralManager alloc] init];
CBManagerAuthorization blePermission = [manager authorization];
CBManagerAuthorization blePermission = [_centralManager authorization];
return [BluetoothPermissionStrategy parsePermission:blePermission];
}
return PermissionStatusGranted;
}
- (ServiceStatus)checkServiceStatus:(PermissionGroup)permission {
CBCentralManager* manager = [[CBCentralManager alloc] init];
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 {
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)){
......@@ -43,11 +61,17 @@
case CBManagerAuthorizationRestricted:
return PermissionStatusRestricted;
case CBManagerAuthorizationDenied:
return PermissionStatusDenied;
return PermissionStatusPermanentlyDenied;
case CBManagerAuthorizationAllowedAlways:
return PermissionStatusGranted;
}
}
- (void)centralManagerDidUpdateState:(nonnull CBCentralManager *)centralManager {
PermissionStatus permissionStatus = [self checkPermissionStatus:_requestedPermission];
_permissionStatusHandler(permissionStatus);
}
@end
#else
......
name: permission_handler
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
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