dpa99c / cordova-diagnostic-plugin

Cordova/Phonegap plugin to manage device settings
539 stars 361 forks source link

Plugin returns `denied_always` at first, when choosing `Select photos` permission on iOS 14+ #476

Closed dcxn closed 2 years ago

dcxn commented 2 years ago

Bug report

CHECKLIST

Current behavior:

As mentioned in this closed issue, on a fresh install of the app on iOS, when the user gets prompted to give access to camera roll and chooses Select photos... option and once you close the native popup where you select the photos, the plugin returns denied_always as permission status. Only on the second time of trying to select a photo, it will return the proper permission limited.

// example code inspired by the plugin doc snippets
cordova.plugins.diagnostic.getCameraRollAuthorizationStatus(function (authorizationStatus) {
    switch (authorizationStatus) {
        case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
            console.log("Permission not requested");
            cordova.plugins.diagnostic.requestCameraRollAuthorization(function(status){
                console.log("status", status) // Output: "status denied_always"
                switch(status){
                    case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                        console.log("Permission denied");
                        break;
                    case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                        console.log("Permission granted to access all photos");
                        break;
                    case cordova.plugins.diagnostic.permissionStatus.LIMITED: // iOS 14+
                        console.log("Permission granted to access limited set of photos");
                        break;
                }
            }, function(error){
                console.error(error);
            }, cordova.plugins.diagnostic.photoLibraryAccessLevel.READ_WRITE);
            break;
        default:
            break;
    }
});

Expected behavior:

Plugin returns limited status when the user chooses to give Select photos permission on clean install.

Steps to reproduce:

Use the short code snippet, choose Select photos as permission.

Environment information

Runtime issue

Thank you

expcapitaldev commented 2 years ago

he all, for requestCameraRollAuthorization with limited will be return denied_always, https://github.com/dpa99c/cordova-diagnostic-plugin/blob/7.1.0/www/ios/diagnostic.camera.js#L226 but in documentation is limited , see https://github.com/dpa99c/cordova-diagnostic-plugin#example-usage-54

expcapitaldev commented 2 years ago

olso accessLevel as string is required on iOS

dpa99c commented 2 years ago

Fix released in cordova.plugins.diagnostic@7.1.1