Skip to content

Commit

Permalink
Adds support for StoragePermissionStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Gregor committed Nov 6, 2019
1 parent f24a2aa commit 4a1d3a4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 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 "PermissionHandlerEnums.h"
#import "Codec.h"
Expand All @@ -28,13 +29,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
28 changes: 15 additions & 13 deletions ios/Classes/PermissionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,32 @@ + (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 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

0 comments on commit 4a1d3a4

Please sign in to comment.