Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions permission_handler_apple/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 9.5.0

* Migrates iOS platform communication from MethodChannel to Pigeon.
* Adds Dart platform implementation `PermissionHandlerApple` registered via `dartPluginClass`.
* Removes the legacy iOS MethodChannel handler.
* Increases minimum supported Dart SDK version to 3.3.0 to be compatible with pigeon dependency

## 9.4.10

* Fixed Info.plist lookup in Package.swift to auto-apply permissions.
Expand Down
10 changes: 10 additions & 0 deletions permission_handler_apple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ Since version 9.1.0 of the [permission_handler](https://pub.dev/packages/permiss

More detailed instructions on using the API can be found in the [README.md](../permission_handler/README.md) of the [permission_handler](https://pub.dev/packages/permission_handler) package.

## Development

iOS platform communication uses [Pigeon](https://pub.dev/packages/pigeon). After changing [`pigeon/permission_handler_apple_api.dart`](pigeon/permission_handler_apple_api.dart), regenerate native and Dart bindings from this package directory:

```bash
dart run pigeon --input pigeon/permission_handler_apple_api.dart
```

Commit the generated files under `lib/src/pigeon/` and `ios/permission_handler_apple/Sources/permission_handler_apple/pigeon/`.

## Issues

Please file any issues, bugs, or feature requests as an issue on our [GitHub](https://github.com/Baseflow/flutter-permission-handler/issues) page. Commercial support is available, you can contact us at <hello@baseflow.com>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'permission_handler_apple'
s.version = '9.4.8'
s.version = '9.5.0'
s.summary = 'Permission plugin for Flutter.'
s.description = <<-DESC
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ let package = Package(
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("."),
.headerSearchPath("pigeon"),
.headerSearchPath("strategies"),
.headerSearchPath("util"),
.headerSearchPath("include/permission_handler_apple"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,84 @@
#import "PermissionHandlerPlugin.h"
#import "PermissionHandlerAppleApi.h"
#import "Codec.h"

@interface PermissionHandlerPlugin () <PHPermissionHandlerHostApi>
@end

@implementation PermissionHandlerPlugin {
PermissionManager *_Nonnull _permissionManager;
_Nullable FlutterResult _methodResult;
BOOL _permissionRequestInProgress;
}

- (instancetype)initWithPermissionManager:(PermissionManager *)permissionManager {
self = [super init];
if (self) {
_permissionManager = permissionManager;
}

return self;
}

+ (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:@"flutter.baseflow.com/permissions/methods"
binaryMessenger:[registrar messenger]];
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
PermissionManager *permissionManager = [[PermissionManager alloc] initWithStrategyInstances];
PermissionHandlerPlugin *instance = [[PermissionHandlerPlugin alloc] initWithPermissionManager:permissionManager];
[registrar addMethodCallDelegate:instance channel:channel];
SetUpPHPermissionHandlerHostApi([registrar messenger], instance);
}

#pragma mark - PHPermissionHandlerHostApi

- (nullable NSNumber *)checkPermissionStatusPermission:(NSInteger)permission
error:(FlutterError *_Nullable *_Nonnull)error {
__block NSNumber *statusResult = nil;
[PermissionManager checkPermissionStatus:(PermissionGroup)permission
result:^(id result) {
statusResult = result;
}];
return statusResult;
}

- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"checkPermissionStatus" isEqualToString:call.method]) {
PermissionGroup permission = [Codec decodePermissionGroupFrom:call.arguments];
[PermissionManager checkPermissionStatus:permission result:result];
} else if ([@"checkServiceStatus" isEqualToString:call.method]) {
PermissionGroup permission = [Codec decodePermissionGroupFrom:call.arguments];
[PermissionManager checkServiceStatus:permission result:result];
} else if ([@"requestPermissions" isEqualToString:call.method]) {
if (_methodResult != nil) {
result([FlutterError errorWithCode:@"ERROR_ALREADY_REQUESTING_PERMISSIONS" message:@"A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time)." details:nil]);
return;
}

_methodResult = result;
NSArray *permissions = [Codec decodePermissionGroupsFrom:call.arguments];

[_permissionManager
requestPermissions:permissions completion:^(NSDictionary *permissionRequestResults) {
if (self->_methodResult != nil) {
self->_methodResult(permissionRequestResults);
}

self->_methodResult = nil;
} errorHandler:^(NSString *errorCode, NSString *errorDescription) {
self->_methodResult([FlutterError errorWithCode:errorCode message:errorDescription details:nil]);
self->_methodResult = nil;
}
];

} else if ([@"shouldShowRequestPermissionRationale" isEqualToString:call.method]) {
result(@false);
} else if ([@"openAppSettings" isEqualToString:call.method]) {
[PermissionManager openAppSettings:result];
} else {
result(FlutterMethodNotImplemented);
- (void)checkServiceStatusPermission:(NSInteger)permission
completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion {
[PermissionManager checkServiceStatus:(PermissionGroup)permission
result:^(id result) {
completion(result, nil);
}];
}

- (void)requestPermissionsPermissions:(NSArray<NSNumber *> *)permissions
completion:(void (^)(NSDictionary<NSNumber *, NSNumber *> *_Nullable,
FlutterError *_Nullable))completion {
if (_permissionRequestInProgress) {
completion(nil, [FlutterError
errorWithCode:@"ERROR_ALREADY_REQUESTING_PERMISSIONS"
message:@"A request for permissions is already running, please wait for it to "
@"finish before doing another request (note that you can request "
@"multiple permissions at the same time)."
details:nil]);
return;
}

_permissionRequestInProgress = YES;
NSArray *permissionGroups = [Codec decodePermissionGroupsFrom:permissions];

[_permissionManager
requestPermissions:permissionGroups
completion:^(NSDictionary *permissionRequestResults) {
self->_permissionRequestInProgress = NO;
completion(permissionRequestResults, nil);
}
errorHandler:^(NSString *errorCode, NSString *errorDescription) {
self->_permissionRequestInProgress = NO;
completion(nil, [FlutterError errorWithCode:errorCode
message:errorDescription
details:nil]);
}];
}

- (void)openAppSettingsWithCompletion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion {
[PermissionManager openAppSettings:^(id result) {
completion(result, nil);
}];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Autogenerated from Pigeon (v27.1.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

@import Foundation;

@protocol FlutterBinaryMessenger;
@protocol FlutterMessageCodec;
@class FlutterError;
@class FlutterStandardTypedData;

NS_ASSUME_NONNULL_BEGIN


/// The codec used by all APIs.
NSObject<FlutterMessageCodec> *PHGetPermissionHandlerAppleApiCodec(void);

@protocol PHPermissionHandlerHostApi
/// @return `nil` only when `error != nil`.
- (nullable NSNumber *)checkPermissionStatusPermission:(NSInteger)permission error:(FlutterError *_Nullable *_Nonnull)error;
- (void)checkServiceStatusPermission:(NSInteger)permission completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
- (void)requestPermissionsPermissions:(NSArray<NSNumber *> *)permissions completion:(void (^)(NSDictionary<NSNumber *, NSNumber *> *_Nullable, FlutterError *_Nullable))completion;
- (void)openAppSettingsWithCompletion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
@end

extern void SetUpPHPermissionHandlerHostApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<PHPermissionHandlerHostApi> *_Nullable api);

extern void SetUpPHPermissionHandlerHostApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger, NSObject<PHPermissionHandlerHostApi> *_Nullable api, NSString *messageChannelSuffix);

NS_ASSUME_NONNULL_END
Loading
Loading