Skip to content

Commit

Permalink
Merge pull request Baseflow#170 from phranck/develop
Browse files Browse the repository at this point in the history
Adds support for StoragePermissionStrategy on iOS
  • Loading branch information
mvanbeusekom authored Nov 8, 2019
2 parents 9dfed04 + b0e3f87 commit e3d7818
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
6 changes: 2 additions & 4 deletions ios/Classes/PermissionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "PhotoPermissionStrategy.h"
#import "SensorPermissionStrategy.h"
#import "SpeechPermissionStrategy.h"
#import "StoragePermissionStrategy.h"
#import "UnknownPermissionStrategy.h"
#import "NotificationPermissionStrategy.h"
#import "PermissionHandlerEnums.h"
Expand All @@ -29,13 +30,10 @@ typedef void (^PermissionRequestCompletion)(NSDictionary *permissionRequestResul
@interface PermissionManager : NSObject

- (instancetype)initWithStrategyInstances;
- (void)requestPermissions:(NSArray *)permissions completion:(PermissionRequestCompletion)completion;

+ (void)checkPermissionStatus:(enum PermissionGroup)permission result:(FlutterResult)result;

+ (void)checkServiceStatus:(enum PermissionGroup)permission result:(FlutterResult)result;

+ (void)openAppSettings:(FlutterResult)result;

- (void)requestPermissions:(NSArray *)permissions completion:(PermissionRequestCompletion)completion;

@end
30 changes: 16 additions & 14 deletions ios/Classes/PermissionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,34 @@ + (void)openAppSettings:(FlutterResult)result {

+ (id)createPermissionStrategy:(PermissionGroup)permission {
switch (permission) {
case PermissionGroupCalendar:
case PermissionGroupCalendar:
return [EventPermissionStrategy new];
case PermissionGroupCamera:
case PermissionGroupCamera:
return [AudioVideoPermissionStrategy new];
case PermissionGroupContacts:
case PermissionGroupContacts:
return [ContactPermissionStrategy new];
case PermissionGroupLocation:
case PermissionGroupLocationAlways:
case PermissionGroupLocationWhenInUse:
case PermissionGroupLocation:
case PermissionGroupLocationAlways:
case PermissionGroupLocationWhenInUse:
return [[LocationPermissionStrategy alloc] initWithLocationManager];
case PermissionGroupMediaLibrary:
case PermissionGroupMediaLibrary:
return [MediaLibraryPermissionStrategy new];
case PermissionGroupMicrophone:
case PermissionGroupMicrophone:
return [AudioVideoPermissionStrategy new];
case PermissionGroupPhone:
case PermissionGroupPhone:
return [PhonePermissionStrategy new];
case PermissionGroupPhotos:
case PermissionGroupPhotos:
return [PhotoPermissionStrategy new];
case PermissionGroupReminders:
case PermissionGroupReminders:
return [EventPermissionStrategy new];
case PermissionGroupSensors:
case PermissionGroupSensors:
return [SensorPermissionStrategy new];
case PermissionGroupSpeech:
case PermissionGroupSpeech:
return [SpeechPermissionStrategy new];
case PermissionGroupNotification:
case PermissionGroupNotification:
return [NotificationPermissionStrategy new];
case PermissionGroupStorage:
return [StoragePermissionStrategy new];
default:
return [UnknownPermissionStrategy new];
}
Expand Down
17 changes: 17 additions & 0 deletions ios/Classes/strategies/StoragePermissionStrategy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// StoragePermissionStrategy.h
// permission_handler
//
// Created by Frank Gregor on 06.11.19.
//

#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"

NS_ASSUME_NONNULL_BEGIN

@interface StoragePermissionStrategy : NSObject <PermissionStrategy>

@end

NS_ASSUME_NONNULL_END
28 changes: 28 additions & 0 deletions ios/Classes/strategies/StoragePermissionStrategy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// StoragePermissionStrategy.m
// permission_handler
//
// Created by Frank Gregor on 06.11.19.
//

#import "StoragePermissionStrategy.h"

@implementation StoragePermissionStrategy

- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
return [StoragePermissionStrategy permissionStatus];
}

- (ServiceStatus)checkServiceStatus:(PermissionGroup)permission {
return ServiceStatusNotApplicable;
}

- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
completionHandler([StoragePermissionStrategy permissionStatus]);
}

+ (PermissionStatus)permissionStatus {
return PermissionStatusGranted;
}

@end
2 changes: 1 addition & 1 deletion lib/src/permission_enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class PermissionGroup {
static const PermissionGroup speech = PermissionGroup._(13);

/// Android: External Storage
/// iOS: Nothing
/// iOS: Access to folders like `Documents` or `Downloads`. Implicitly granted.
static const PermissionGroup storage = PermissionGroup._(14);

/// Android: Ignore Battery Optimizations
Expand Down

0 comments on commit e3d7818

Please sign in to comment.