Commit 9d12bb54 by Rene Floor

Add bluetooth permission.

parent e89eaa91
......@@ -108,7 +108,9 @@ typedef NS_ENUM(int, PermissionGroup) {
PermissionGroupIgnoreBatteryOptimizations,
PermissionGroupNotification,
PermissionGroupAccessMediaLocation,
PermissionGroupActivityRecognition,
PermissionGroupUnknown,
PermissionGroupBluetooth,
};
typedef NS_ENUM(int, PermissionStatus) {
......
......@@ -10,6 +10,7 @@
#import <UIKit/UIKit.h>
#import "AudioVideoPermissionStrategy.h"
#import "BluetoothPermissionStrategy.h"
#import "ContactPermissionStrategy.h"
#import "EventPermissionStrategy.h"
#import "LocationPermissionStrategy.h"
......
......@@ -123,6 +123,8 @@
return [NotificationPermissionStrategy new];
case PermissionGroupStorage:
return [StoragePermissionStrategy new];
case PermissionGroupBluetooth:
return [BluetoothPermissionStrategy new];
default:
return [UnknownPermissionStrategy new];
}
......
//
// BluetoothPermissionStrategy.h
// permission_handler
//
// Created by Rene Floor on 12/03/2021.
//
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "PermissionStrategy.h"
@interface BluetoothPermissionStrategy : NSObject <PermissionStrategy>
@end
//
// BluetoothPermissionStrategy.m
// permission_handler
//
// Created by Rene Floor on 12/03/2021.
//
#import "BluetoothPermissionStrategy.h"
@implementation BluetoothPermissionStrategy
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
if (@available(iOS 13.1, *)) {
CBManagerAuthorization blePermission = [CBCentralManager authorization];
return [BluetoothPermissionStrategy parsePermission:blePermission];
} else if (@available(iOS 13.0, *)){
CBCentralManager* manager = [[CBCentralManager alloc] init];
CBManagerAuthorization blePermission = [manager 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 [manager state] == CBCentralManagerStatePoweredOn ? ServiceStatusEnabled : ServiceStatusDisabled;
}
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
completionHandler([self checkPermissionStatus:permission]);
}
+ (PermissionStatus)parsePermission:(CBManagerAuthorization)bluetoothPermission API_AVAILABLE(ios(13)){
switch(bluetoothPermission){
case CBManagerAuthorizationNotDetermined:
return PermissionStatusDenied;
case CBManagerAuthorizationRestricted:
return PermissionStatusRestricted;
case CBManagerAuthorizationDenied:
return PermissionStatusDenied;
case CBManagerAuthorizationAllowedAlways:
return PermissionStatusGranted;
}
}
@end
......@@ -16,7 +16,8 @@ dependencies:
flutter:
sdk: flutter
meta: ^1.3.0
permission_handler_platform_interface: ^3.0.0+1
permission_handler_platform_interface:
path: ../permission_handler_platform_interface
dev_dependencies:
effective_dart: ^1.3.0
......
......@@ -103,6 +103,10 @@ class Permission {
/// The unknown only used for return type, never requested
static const unknown = Permission._(20);
/// iOS 13 and above: The authorization state of Core Bluetooth manager.
/// When running < iOS 13 or Android this is always allowed.
static const bluetooth = Permission._(21);
/// Returns a list of all possible [PermissionGroup] values.
static const List<Permission> values = <Permission>[
calendar,
......@@ -126,6 +130,7 @@ class Permission {
accessMediaLocation,
activityRecognition,
unknown,
bluetooth
];
static const List<String> _names = <String>[
......@@ -150,6 +155,7 @@ class Permission {
'access_media_location',
'activity_recognition',
'unknown',
'bluetooth',
];
@override
......
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