Commit 1e17edd9 by Jan-Derk

Merge remote-tracking branch 'origin/master' into implementing_tests

parents acd89555 900f8dea
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
### :thinking: Checklist before submitting ### :thinking: Checklist before submitting
- [ ] All projects build - [ ] I made sure all projects build.
- [ ] Follows style guide lines ([code style guide](https://github.com/Baseflow/flutter-permission-handler/blob/develop/CONTRIBUTING.md)) - [ ] I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy](https://dart.dev/tools/pub/versioning).
- [ ] Relevant documentation was updated - [ ] I updated CHANGELOG.md to add a description of the change.
- [ ] Rebased onto current develop - [ ] I followed the style guide lines ([code style guide](https://github.com/Baseflow/flutter-permission-handler/blob/develop/CONTRIBUTING.md)).
- [ ] I updated the relevant documentation.
- [ ] I rebased onto current `master`.
...@@ -58,3 +58,15 @@ jobs: ...@@ -58,3 +58,15 @@ jobs:
- name: Run iOS build - name: Run iOS build
run: flutter build ios --release --no-codesign run: flutter build ios --release --no-codesign
working-directory: ${{env.example-directory}} working-directory: ${{env.example-directory}}
# Run all unit-tests with code coverage
- name: Run unit tests
run: flutter test --coverage
working-directory: ${{env.source-directory}}
# Upload code coverage information
- uses: codecov/codecov-action@v1
with:
file: ${{env.source-directory}}/coverage/lcov.info # optional
name: permission_handler (Platform Interface Package) # optional
fail_ci_if_error: true
...@@ -47,4 +47,16 @@ jobs: ...@@ -47,4 +47,16 @@ jobs:
- name: Run Flutter Analyzer - name: Run Flutter Analyzer
run: flutter analyze run: flutter analyze
working-directory: ${{env.source-directory}} working-directory: ${{env.source-directory}}
# Run all unit-tests with code coverage
- name: Run unit tests
run: flutter test --coverage
working-directory: ${{env.source-directory}}
# Upload code coverage information
- uses: codecov/codecov-action@v1
with:
file: ${{env.source-directory}}/coverage/lcov.info # optional
name: permission_handler (Platform Interface Package) # optional
fail_ci_if_error: true
...@@ -101,6 +101,9 @@ You can remove permissions you don't use: ...@@ -101,6 +101,9 @@ You can remove permissions you don't use:
## dart: PermissionGroup.sensors ## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=0' # 'PERMISSION_SENSORS=0'
## dart: PermissionGroup.bluetooth
# 'PERMISSION_BLUETOOTH=0'
] ]
end end
...@@ -128,6 +131,7 @@ You can remove permissions you don't use: ...@@ -128,6 +131,7 @@ You can remove permissions you don't use:
| PermissionGroup.notification | PermissionGroupNotification | PERMISSION_NOTIFICATIONS | | PermissionGroup.notification | PermissionGroupNotification | PERMISSION_NOTIFICATIONS |
| PermissionGroup.mediaLibrary | NSAppleMusicUsageDescription, kTCCServiceMediaLibrary | PERMISSION_MEDIA_LIBRARY | | PermissionGroup.mediaLibrary | NSAppleMusicUsageDescription, kTCCServiceMediaLibrary | PERMISSION_MEDIA_LIBRARY |
| PermissionGroup.sensors | NSMotionUsageDescription | PERMISSION_SENSORS | | PermissionGroup.sensors | NSMotionUsageDescription | PERMISSION_SENSORS |
| PermissionGroup.bluetooth | NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription | PERMISSION_BLUETOOTH |
4. Clean & Rebuild 4. Clean & Rebuild
</details> </details>
......
## 6.1.0
* Added support for bluetooth permissions;
* Workaround for ignore battery optimizations on pre-M Android devices (see PR [#376](https://github.com/Baseflow/flutter-permission-handler/pull/376)).
## 6.0.1+1
* Fixed content of the README.md file.
## 6.0.1 ## 6.0.1
* Fixed deprecation warning when building Android project. * Fixed deprecation warning when building Android project.
......
# permission_handler_platform_interface [![pub package](https://img.shields.io/pub/v/permission_handler.svg)](https://pub.dartlang.org/packages/permission_handler) [![Build status](https://github.com/Baseflow/flutter-permission-handler/actions/workflows/app_facing_package.yaml/badge.svg?branch=master)](https://github.com/Baseflow/flutter-permission-handler/actions/workflows/app_facing_package.yaml) [![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://github.com/tenhobi/effective_dart)
[![pub package](https://img.shields.io/pub/v/permission_handler.svg)](https://pub.dartlang.org/packages/permission_handler) ![Build status](https://github.com/Baseflow/flutter-permission-handler/workflows/app_facing_package/badge.svg?branch=master) [![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://github.com/tenhobi/effective_dart) On most operating systems, permissions aren't just granted to apps at install time.
Rather, developers have to ask the user for permissions while the app is running.
A common platform interface for the [`permission_handler`][1] plugin. This plugin provides a cross-platform (iOS, Android) API to request permissions and check their status.
You can also open the device's app settings so users can grant a permission.
On Android, you can show a rationale for requesting a permission.
This interface allows platform-specific implementations of the `permission_handler` ## Setup
plugin, as well as the plugin itself, to ensure they are supporting the
same interface. Have a look at the [Federated plugins](https://flutter.dev/docs/development/packages-and-plugins/developing-packages#federated-plugins)
section of the official [Developing packages & plugins](https://flutter.dev/docs/development/packages-and-plugins/developing-packages)
documentation for more information regarding the federated architecture concept.
## Usage While the permissions are being requested during runtime, you'll still need to tell the OS which permissions your app might potentially use. That requires adding permission configuration to Android- and iOS-specific files.
To implement a new platform-specific implementation of `permission_handler`, extend <details>
[`PermissionHandlerPlatform`][2] with an implementation that performs the <summary>Android</summary>
platform-specific behavior, and when you register your plugin, set the default
`PermissionHandlerPlatform` by calling **Upgrade pre 1.12 Android projects**
`PermissionHandlerPlatform.instance = MyPlatformPermissionHandler()`.
Since version 4.4.0 this plugin is implemented using the Flutter 1.12 Android plugin APIs. Unfortunately this means App developers also need to migrate their Apps to support the new Android infrastructure. You can do so by following the [Upgrading pre 1.12 Android projects](https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects) migration guide. Failing to do so might result in unexpected behaviour. Most common known error is the permission_handler not returning after calling the `.request()` method on a permission.
## Note on breaking changes **AndroidX**
Strongly prefer non-breaking changes (such as adding a method to the interface) As of version 3.1.0 the <kbd>permission_handler</kbd> plugin switched to the AndroidX version of the Android Support Libraries. This means you need to make sure your Android project is also upgraded to support AndroidX. Detailed instructions can be found [here](https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility).
over breaking changes for this package.
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion The TL;DR version is:
on why a less-clean interface is preferable to a breaking change. 1. Add the following to your "gradle.properties" file:
```
android.useAndroidX=true
android.enableJetifier=true
```
2. Make sure you set the `compileSdkVersion` in your "android/app/build.gradle" file to 28:
```
android {
compileSdkVersion 28
...
}
```
3. Make sure you replace all the `android.` dependencies to their AndroidX counterparts (a full list can be found here: https://developer.android.com/jetpack/androidx/migrate).
Add permissions to your `AndroidManifest.xml` file.
There's a `debug`, `main` and `profile` version which are chosen depending on how you start your app.
In general, it's sufficient to add permission only to the `main` version.
[Here](https://github.com/Baseflow/flutter-permission-handler/blob/develop/permission_handler/example/android/app/src/main/AndroidManifest.xml)'s an example `AndroidManifest.xml` with a complete list of all possible permissions.
</details>
<details>
<summary>iOS</summary>
Add permission to your `Info.plist` file.
[Here](https://github.com/Baseflow/flutter-permission-handler/blob/develop/permission_handler/example/ios/Runner/Info.plist)'s an example `Info.plist` with a complete list of all possible permissions.
> IMPORTANT: ~~You will have to include all permission options when you want to submit your App.~~ This is because the `permission_handler` plugin touches all different SDKs and because the static code analyser (run by Apple upon App submission) detects this and will assert if it cannot find a matching permission option in the `Info.plist`. More information about this can be found [here](https://github.com/BaseflowIT/flutter-permission-handler/issues/26).
The <kbd>permission_handler</kbd> plugin use [macros](https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/permission_handler/ios/Classes/PermissionHandlerEnums.h) to control whether a permission is supported.
You can remove permissions you don't use:
1. Add the following to your `Podfile` file:
```ruby
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
... # Here are some configurations automatically generated by flutter
# You can remove unused permissions here
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/permission_handler/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.calendar
# 'PERMISSION_EVENTS=0',
## dart: PermissionGroup.reminders
# 'PERMISSION_REMINDERS=0',
## dart: PermissionGroup.contacts
# 'PERMISSION_CONTACTS=0',
## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=0',
## dart: PermissionGroup.microphone
# 'PERMISSION_MICROPHONE=0',
## dart: PermissionGroup.speech
# 'PERMISSION_SPEECH_RECOGNIZER=0',
## dart: PermissionGroup.photos
# 'PERMISSION_PHOTOS=0',
## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
# 'PERMISSION_LOCATION=0',
## dart: PermissionGroup.notification
# 'PERMISSION_NOTIFICATIONS=0',
## dart: PermissionGroup.mediaLibrary
# 'PERMISSION_MEDIA_LIBRARY=0',
## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=0'
]
end
end
end
```
2. Remove the `#` character in front of the permission you do not want to use. For example if you don't need access to the calendar make sure the code looks like this:
```ruby
## dart: PermissionGroup.calendar
'PERMISSION_EVENTS=0',
```
3. Delete the corresponding permission description in `Info.plist`
e.g. when you don't need camera permission, just delete 'NSCameraUsageDescription'
The following lists the relationship between `Permission` and `The key of Info.plist`:
| Permission | Info.plist | Macro |
| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------- |
| PermissionGroup.calendar | NSCalendarsUsageDescription | PERMISSION_EVENTS |
| PermissionGroup.reminders | NSRemindersUsageDescription | PERMISSION_REMINDERS |
| PermissionGroup.contacts | NSContactsUsageDescription | PERMISSION_CONTACTS |
| PermissionGroup.camera | NSCameraUsageDescription | PERMISSION_CAMERA |
| PermissionGroup.microphone | NSMicrophoneUsageDescription | PERMISSION_MICROPHONE |
| PermissionGroup.speech | NSSpeechRecognitionUsageDescription | PERMISSION_SPEECH_RECOGNIZER |
| PermissionGroup.photos | NSPhotoLibraryUsageDescription | PERMISSION_PHOTOS |
| PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse | NSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription | PERMISSION_LOCATION |
| PermissionGroup.notification | PermissionGroupNotification | PERMISSION_NOTIFICATIONS |
| PermissionGroup.mediaLibrary | NSAppleMusicUsageDescription, kTCCServiceMediaLibrary | PERMISSION_MEDIA_LIBRARY |
| PermissionGroup.sensors | NSMotionUsageDescription | PERMISSION_SENSORS |
4. Clean & Rebuild
</details>
## How to use
There are a number of [`Permission`](https://pub.dev/documentation/permission_handler_platform_interface/latest/permission_handler_platform_interface/Permission-class.html#constants)s.
You can get a `Permission`'s `status`, which is either `granted`, `denied`, `restricted` or `permanentlyDenied`.
```dart
var status = await Permission.camera.status;
if (status.denied) {
// We didn't ask for permission yet or the permission has been denied before but not permanently.
}
// You can can also directly ask the permission about its status.
if (await Permission.location.isRestricted) {
// The OS restricts access, for example because of parental controls.
}
```
Call `request()` on a `Permission` to request it.
If it has already been granted before, nothing happens.
`request()` returns the new status of the `Permission`.
```dart
if (await Permission.contacts.request().isGranted) {
// Either the permission was already granted before or the user just granted it.
}
// You can request multiple permissions at once.
Map<Permission, PermissionStatus> statuses = await [
Permission.location,
Permission.storage,
].request();
print(statuses[Permission.location]);
```
Some permissions, for example location or acceleration sensor permissions, have an associated service, which can be `enabled` or `disabled`.
```dart
if (await Permission.locationWhenInUse.serviceStatus.isEnabled) {
// Use location.
}
```
You can also open the app settings:
```dart
if (await Permission.speech.isPermanentlyDenied) {
// The user opted to never again see the permission request dialog for this
// app. The only way to change the permission's status now is to let the
// user manually enable it in the system settings.
openAppSettings();
}
```
On Android, you can show a rationale for using a permission:
```dart
bool isShown = await Permission.contacts.shouldShowRequestRationale;
```
## Issues ## Issues
Please file any issues, bugs or feature request as an issue on our [GitHub](https://github.com/Baseflow/flutter-permission-handler/issues) page. Please file any issues, bugs or feature request as an issue on our [GitHub](https://github.com/Baseflow/flutter-permission-handler/issues) page. Commercial support is available if you need help with integration with your app or services. You can contact us at [hello@baseflow.com](mailto:hello@baseflow.com).
## Want to contribute ## Want to contribute
......
...@@ -32,6 +32,7 @@ final class PermissionConstants { ...@@ -32,6 +32,7 @@ final class PermissionConstants {
static final int PERMISSION_GROUP_ACCESS_MEDIA_LOCATION = 18; static final int PERMISSION_GROUP_ACCESS_MEDIA_LOCATION = 18;
static final int PERMISSION_GROUP_ACTIVITY_RECOGNITION = 19; static final int PERMISSION_GROUP_ACTIVITY_RECOGNITION = 19;
static final int PERMISSION_GROUP_UNKNOWN = 20; static final int PERMISSION_GROUP_UNKNOWN = 20;
static final int PERMISSION_GROUP_BLUETOOTH = 21;
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({ @IntDef({
...@@ -55,6 +56,7 @@ final class PermissionConstants { ...@@ -55,6 +56,7 @@ final class PermissionConstants {
PERMISSION_GROUP_ACCESS_MEDIA_LOCATION, PERMISSION_GROUP_ACCESS_MEDIA_LOCATION,
PERMISSION_GROUP_ACTIVITY_RECOGNITION, PERMISSION_GROUP_ACTIVITY_RECOGNITION,
PERMISSION_GROUP_UNKNOWN, PERMISSION_GROUP_UNKNOWN,
PERMISSION_GROUP_BLUETOOTH,
}) })
@interface PermissionGroup { @interface PermissionGroup {
} }
......
...@@ -104,7 +104,13 @@ final class PermissionManager { ...@@ -104,7 +104,13 @@ final class PermissionManager {
// if we can't add as unknown and continue // if we can't add as unknown and continue
if (names == null || names.isEmpty()) { if (names == null || names.isEmpty()) {
if (!requestResults.containsKey(permission)) { if (!requestResults.containsKey(permission)) {
requestResults.put(permission, PermissionConstants.PERMISSION_STATUS_DENIED); // On Android below M, the android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS flag in AndroidManifest.xml
// may be ignored and not visible to the App as it's a new permission setting as a whole.
if (permission == PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
requestResults.put(permission, PermissionConstants.PERMISSION_STATUS_RESTRICTED);
} else {
requestResults.put(permission, PermissionConstants.PERMISSION_STATUS_DENIED);
}
} }
continue; continue;
...@@ -160,6 +166,9 @@ final class PermissionManager { ...@@ -160,6 +166,9 @@ final class PermissionManager {
if (permission == PermissionConstants.PERMISSION_GROUP_NOTIFICATION) { if (permission == PermissionConstants.PERMISSION_GROUP_NOTIFICATION) {
return checkNotificationPermissionStatus(context); return checkNotificationPermissionStatus(context);
} }
if(permission == PermissionConstants.PERMISSION_GROUP_BLUETOOTH){
return checkBluetoothPermissionStatus(context);
}
final List<String> names = PermissionUtils.getManifestNames(context, permission); final List<String> names = PermissionUtils.getManifestNames(context, permission);
...@@ -172,6 +181,15 @@ final class PermissionManager { ...@@ -172,6 +181,15 @@ final class PermissionManager {
//if no permissions were found then there is an issue and permission is not set in Android manifest //if no permissions were found then there is an issue and permission is not set in Android manifest
if (names.size() == 0) { if (names.size() == 0) {
Log.d(PermissionConstants.LOG_TAG, "No permissions found in manifest for: " + permission); Log.d(PermissionConstants.LOG_TAG, "No permissions found in manifest for: " + permission);
// On Android below M, the android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS flag in AndroidManifest.xml
// may be ignored and not visible to the App as it's a new permission setting as a whole.
if (permission == PermissionConstants.PERMISSION_GROUP_IGNORE_BATTERY_OPTIMIZATIONS) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return PermissionConstants.PERMISSION_STATUS_RESTRICTED;
}
}
return PermissionConstants.PERMISSION_STATUS_DENIED; return PermissionConstants.PERMISSION_STATUS_DENIED;
} }
...@@ -244,6 +262,16 @@ final class PermissionManager { ...@@ -244,6 +262,16 @@ final class PermissionManager {
return PermissionConstants.PERMISSION_STATUS_DENIED; return PermissionConstants.PERMISSION_STATUS_DENIED;
} }
private int checkBluetoothPermissionStatus(Context context) {
List<String> names = PermissionUtils.getManifestNames(context, PermissionConstants.PERMISSION_GROUP_BLUETOOTH);
boolean missingInManifest = names == null || names.isEmpty();
if(missingInManifest) {
Log.d(PermissionConstants.LOG_TAG, "Bluetooth permission missing in manifest");
return PermissionConstants.PERMISSION_STATUS_DENIED;
}
return PermissionConstants.PERMISSION_STATUS_GRANTED;
}
@VisibleForTesting @VisibleForTesting
static final class ActivityResultListener static final class ActivityResultListener
implements PluginRegistry.ActivityResultListener { implements PluginRegistry.ActivityResultListener {
......
...@@ -193,6 +193,10 @@ public class PermissionUtils { ...@@ -193,6 +193,10 @@ public class PermissionUtils {
permissionNames.add(Manifest.permission.ACTIVITY_RECOGNITION); permissionNames.add(Manifest.permission.ACTIVITY_RECOGNITION);
break; break;
case PermissionConstants.PERMISSION_GROUP_BLUETOOTH:
if (hasPermissionInManifest(context, permissionNames, Manifest.permission.BLUETOOTH))
permissionNames.add(Manifest.permission.BLUETOOTH);
break;
case PermissionConstants.PERMISSION_GROUP_NOTIFICATION: case PermissionConstants.PERMISSION_GROUP_NOTIFICATION:
case PermissionConstants.PERMISSION_GROUP_MEDIA_LIBRARY: case PermissionConstants.PERMISSION_GROUP_MEDIA_LIBRARY:
case PermissionConstants.PERMISSION_GROUP_PHOTOS: case PermissionConstants.PERMISSION_GROUP_PHOTOS:
......
package com.baseflow.permissionhandler; package com.baseflow.permissionhandler;
import android.bluetooth.BluetoothAdapter;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
...@@ -43,6 +44,13 @@ final class ServiceManager { ...@@ -43,6 +44,13 @@ final class ServiceManager {
successCallback.onSuccess(serviceStatus); successCallback.onSuccess(serviceStatus);
return; return;
} }
if(permission == PermissionConstants.PERMISSION_GROUP_BLUETOOTH){
final int serviceStatus = isBluetoothServiceEnabled()
? PermissionConstants.SERVICE_STATUS_ENABLED
: PermissionConstants.SERVICE_STATUS_DISABLED;
successCallback.onSuccess(serviceStatus);
}
if (permission == PermissionConstants.PERMISSION_GROUP_PHONE) { if (permission == PermissionConstants.PERMISSION_GROUP_PHONE) {
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
...@@ -139,4 +147,9 @@ final class ServiceManager { ...@@ -139,4 +147,9 @@ final class ServiceManager {
Settings.Secure.LOCATION_PROVIDERS_ALLOWED); Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders); return !TextUtils.isEmpty(locationProviders);
} }
private boolean isBluetoothServiceEnabled() {
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
return bluetoothAdapter.isEnabled();
}
} }
...@@ -60,6 +60,9 @@ ...@@ -60,6 +60,9 @@
<!-- Permissions options for the `ignoreBatteryOptimizations` group --> <!-- Permissions options for the `ignoreBatteryOptimizations` group -->
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<!-- Permissions options for the `bluetooth` group -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<application <application
android:name="io.flutter.app.FlutterApplication" android:name="io.flutter.app.FlutterApplication"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
......
...@@ -88,6 +88,13 @@ ...@@ -88,6 +88,13 @@
#define PERMISSION_SENSORS 1 #define PERMISSION_SENSORS 1
#endif #endif
// ios: PermissionGroupBluetooth
// Info.plist: [NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription]
// dart: PermissionGroup.bluetooth
#ifndef PERMISSION_BLUETOOTH
#define PERMISSION_BLUETOOTH 1
#endif
typedef NS_ENUM(int, PermissionGroup) { typedef NS_ENUM(int, PermissionGroup) {
PermissionGroupCalendar = 0, PermissionGroupCalendar = 0,
PermissionGroupCamera, PermissionGroupCamera,
...@@ -108,7 +115,9 @@ typedef NS_ENUM(int, PermissionGroup) { ...@@ -108,7 +115,9 @@ typedef NS_ENUM(int, PermissionGroup) {
PermissionGroupIgnoreBatteryOptimizations, PermissionGroupIgnoreBatteryOptimizations,
PermissionGroupNotification, PermissionGroupNotification,
PermissionGroupAccessMediaLocation, PermissionGroupAccessMediaLocation,
PermissionGroupActivityRecognition,
PermissionGroupUnknown, PermissionGroupUnknown,
PermissionGroupBluetooth,
}; };
typedef NS_ENUM(int, PermissionStatus) { typedef NS_ENUM(int, PermissionStatus) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AudioVideoPermissionStrategy.h" #import "AudioVideoPermissionStrategy.h"
#import "BluetoothPermissionStrategy.h"
#import "ContactPermissionStrategy.h" #import "ContactPermissionStrategy.h"
#import "EventPermissionStrategy.h" #import "EventPermissionStrategy.h"
#import "LocationPermissionStrategy.h" #import "LocationPermissionStrategy.h"
......
...@@ -123,6 +123,8 @@ ...@@ -123,6 +123,8 @@
return [NotificationPermissionStrategy new]; return [NotificationPermissionStrategy new];
case PermissionGroupStorage: case PermissionGroupStorage:
return [StoragePermissionStrategy new]; return [StoragePermissionStrategy new];
case PermissionGroupBluetooth:
return [BluetoothPermissionStrategy new];
default: default:
return [UnknownPermissionStrategy new]; return [UnknownPermissionStrategy new];
} }
......
//
// BluetoothPermissionStrategy.h
// permission_handler
//
// Created by Rene Floor on 12/03/2021.
//
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"
#if PERMISSION_BLUETOOTH
#import <CoreBluetooth/CoreBluetooth.h>
@interface BluetoothPermissionStrategy : NSObject <PermissionStrategy>
@end
#else
#import "UnknownPermissionStrategy.h"
@interface BluetoothPermissionStrategy : UnknownPermissionStrategy
@end
#endif
//
// BluetoothPermissionStrategy.m
// permission_handler
//
// Created by Rene Floor on 12/03/2021.
//
#import "BluetoothPermissionStrategy.h"
#if PERMISSION_BLUETOOTH
@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
#else
@implementation BluetoothPermissionStrategy
@end
#endif
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: 6.0.1 version: 6.1.0
homepage: https://github.com/baseflowit/flutter-permission-handler homepage: https://github.com/baseflowit/flutter-permission-handler
flutter: flutter:
...@@ -16,7 +16,7 @@ dependencies: ...@@ -16,7 +16,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
meta: ^1.3.0 meta: ^1.3.0
permission_handler_platform_interface: ^3.0.0+1 permission_handler_platform_interface: ^3.1.0
dev_dependencies: dev_dependencies:
effective_dart: ^1.3.0 effective_dart: ^1.3.0
......
## 3.1.0
* Added support for bluetooth permissions.
## 3.0.0+1 ## 3.0.0+1
* **BREAKING**: Removed PermissionStatus.undetermined. This is now replaced by PermissionStatus.denied. * **BREAKING**: Removed PermissionStatus.undetermined. This is now replaced by PermissionStatus.denied.
......
...@@ -109,6 +109,10 @@ class Permission { ...@@ -109,6 +109,10 @@ class Permission {
/// The unknown only used for return type, never requested /// The unknown only used for return type, never requested
static const unknown = Permission._(20); 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. /// Returns a list of all possible [PermissionGroup] values.
static const List<Permission> values = <Permission>[ static const List<Permission> values = <Permission>[
calendar, calendar,
...@@ -132,6 +136,7 @@ class Permission { ...@@ -132,6 +136,7 @@ class Permission {
accessMediaLocation, accessMediaLocation,
activityRecognition, activityRecognition,
unknown, unknown,
bluetooth
]; ];
static const List<String> _names = <String>[ static const List<String> _names = <String>[
...@@ -156,6 +161,7 @@ class Permission { ...@@ -156,6 +161,7 @@ class Permission {
'access_media_location', 'access_media_location',
'activity_recognition', 'activity_recognition',
'unknown', 'unknown',
'bluetooth',
]; ];
@override @override
......
...@@ -3,7 +3,7 @@ description: A common platform interface for the permission_handler plugin. ...@@ -3,7 +3,7 @@ description: A common platform interface for the permission_handler plugin.
homepage: https://github.com/baseflow/flutter-permission-handler/tree/master/permission_handler_platform_interface homepage: https://github.com/baseflow/flutter-permission-handler/tree/master/permission_handler_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a # NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 3.0.0+1 version: 3.1.0
dependencies: dependencies:
flutter: flutter:
...@@ -18,5 +18,5 @@ dev_dependencies: ...@@ -18,5 +18,5 @@ dev_dependencies:
effective_dart: ^1.3.0 effective_dart: ^1.3.0
environment: environment:
sdk: ">=2.12.0-259.9.beta <3.0.0" sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.22.0" flutter: ">=1.22.0"
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