Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: on iOS requestReadPermission returns an invalid result before us… #242

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 22 additions & 6 deletions src/ios/SOSPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 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";
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);
Expand Down