From e4af885a320bd6c7c9158e1e74bc396514793df3 Mon Sep 17 00:00:00 2001 From: Sam Regan Date: Thu, 4 Feb 2021 14:24:18 +1100 Subject: [PATCH 1/2] fix: on iOS requestReadPermission returns an invalid result before user has answered the permission request --- src/ios/SOSPicker.m | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/ios/SOSPicker.m b/src/ios/SOSPicker.m index 0e2e00e7..97ed1b51 100644 --- a/src/ios/SOSPicker.m +++ b/src/ios/SOSPicker.m @@ -49,11 +49,27 @@ - (void) requestReadPermission:(CDVInvokedUrlCommand *)command { CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:message]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } else if (status == PHAuthorizationStatusNotDetermined) { - // Access has not been determined. requestAuthorization: is available - [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {}]; - - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + // Access has not been determined. requestAuthorization: is available, ask. + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { + if (status == PHAuthorizationStatusAuthorized) { + NSLog(@"Access has been granted."); + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } else if (status == PHAuthorizationStatusDenied) { + NSString* message = @"Access has been denied. Change your setting > this app > Photo enable"; + NSLog(@"%@", message); + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:message]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } else if (status == PHAuthorizationStatusRestricted) { + NSString* message = @"Access has been restricted. Change your setting > Privacy > Photo enable"; + NSLog(@"%@", message); + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:message]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } + }]; } else if (status == PHAuthorizationStatusRestricted) { NSString* message = @"Access has been restricted. Change your setting > Privacy > Photo enable"; NSLog(@"%@", message); From 355195caa3f04b03cfdf4481319a7f6d28beb6bc Mon Sep 17 00:00:00 2001 From: Sam Regan Date: Thu, 11 Feb 2021 15:18:32 +1100 Subject: [PATCH 2/2] fix: success callback not passing return value --- src/ios/SOSPicker.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/SOSPicker.m b/src/ios/SOSPicker.m index 97ed1b51..6d81ffd4 100644 --- a/src/ios/SOSPicker.m +++ b/src/ios/SOSPicker.m @@ -40,7 +40,7 @@ - (void) requestReadPermission:(CDVInvokedUrlCommand *)command { if (status == PHAuthorizationStatusAuthorized) { NSLog(@"Access has been granted."); - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:true]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } else if (status == PHAuthorizationStatusDenied) { NSString* message = @"Access has been denied. Change your setting > this app > Photo enable"; @@ -54,7 +54,7 @@ - (void) requestReadPermission:(CDVInvokedUrlCommand *)command { if (status == PHAuthorizationStatusAuthorized) { NSLog(@"Access has been granted."); - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:true]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } else if (status == PHAuthorizationStatusDenied) { NSString* message = @"Access has been denied. Change your setting > this app > Photo enable";