Commit 3a7cf04d by Mathias Cochet

Make separate permission for photo add only accesss level permission.

parent afe1dc2c
...@@ -54,6 +54,13 @@ ...@@ -54,6 +54,13 @@
#define PERMISSION_PHOTOS 1 #define PERMISSION_PHOTOS 1
#endif #endif
// ios: PermissionGroupPhotosAddOnly
// Info.plist: NSPhotoLibraryUsageDescription
// dart: PermissionGroup.photosAddOnly
#ifndef PERMISSION_PHOTOS_ADD_ONLY
#define PERMISSION_PHOTOS_ADD_ONLY
#endif
// ios: [PermissionGroupLocation, PermissionGroupLocationAlways, PermissionGroupLocationWhenInUse] // ios: [PermissionGroupLocation, PermissionGroupLocationAlways, PermissionGroupLocationWhenInUse]
// Info.plist: [NSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription] // Info.plist: [NSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription]
// dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse] // dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
...@@ -92,6 +99,7 @@ typedef NS_ENUM(int, PermissionGroup) { ...@@ -92,6 +99,7 @@ typedef NS_ENUM(int, PermissionGroup) {
PermissionGroupMicrophone, PermissionGroupMicrophone,
PermissionGroupPhone, PermissionGroupPhone,
PermissionGroupPhotos, PermissionGroupPhotos,
PermissionGroupPhotosAddOnly,
PermissionGroupReminders, PermissionGroupReminders,
PermissionGroupSensors, PermissionGroupSensors,
PermissionGroupSms, PermissionGroupSms,
......
...@@ -96,7 +96,9 @@ ...@@ -96,7 +96,9 @@
case PermissionGroupPhone: case PermissionGroupPhone:
return [PhonePermissionStrategy new]; return [PhonePermissionStrategy new];
case PermissionGroupPhotos: case PermissionGroupPhotos:
return [PhotoPermissionStrategy new]; return [[PhotoPermissionStrategy alloc] initWithAccessAddOnly:false];
case PermissionGroupPhotosAddOnly:
return [[PhotoPermissionStrategy alloc] initWithAccessAddOnly:true];
case PermissionGroupReminders: case PermissionGroupReminders:
return [EventPermissionStrategy new]; return [EventPermissionStrategy new];
case PermissionGroupSensors: case PermissionGroupSensors:
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import <Photos/Photos.h> #import <Photos/Photos.h>
@interface PhotoPermissionStrategy : NSObject <PermissionStrategy> @interface PhotoPermissionStrategy : NSObject <PermissionStrategy>
-(instancetype)initWithAccessAddOnly:(BOOL) addOnly;
@end @end
#else #else
......
...@@ -7,9 +7,21 @@ ...@@ -7,9 +7,21 @@
#if PERMISSION_PHOTOS #if PERMISSION_PHOTOS
@implementation PhotoPermissionStrategy @implementation PhotoPermissionStrategy{
bool addOnlyAccessLevel;
}
- (instancetype)initWithAccessAddOnly:(BOOL)addOnly {
self = [super init];
if(self) {
addOnlyAccessLevel = addOnly;
}
return self;
}
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission { - (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
return [PhotoPermissionStrategy permissionStatus]; return [PhotoPermissionStrategy permissionStatus:addOnlyAccessLevel];
} }
- (ServiceStatus)checkServiceStatus:(PermissionGroup)permission { - (ServiceStatus)checkServiceStatus:(PermissionGroup)permission {
...@@ -25,7 +37,7 @@ ...@@ -25,7 +37,7 @@
} }
if(@available(iOS 14, *)) { if(@available(iOS 14, *)) {
[PHPhotoLibrary requestAuthorizationForAccessLevel:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus authorizationStatus) { [PHPhotoLibrary requestAuthorizationForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus authorizationStatus) {
completionHandler([PhotoPermissionStrategy determinePermissionStatus:authorizationStatus]); completionHandler([PhotoPermissionStrategy determinePermissionStatus:authorizationStatus]);
}]; }];
}else { }else {
...@@ -35,10 +47,10 @@ ...@@ -35,10 +47,10 @@
} }
} }
+ (PermissionStatus)permissionStatus { + (PermissionStatus)permissionStatus:(BOOL) addOnlyAccessLevel {
PHAuthorizationStatus status; PHAuthorizationStatus status;
if(@available(iOS 14, *)){ if(@available(iOS 14, *)){
status = [PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite]; status = [PHPhotoLibrary authorizationStatusForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite];
}else { }else {
status = [PHPhotoLibrary authorizationStatus]; status = [PHPhotoLibrary authorizationStatus];
} }
......
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