Diagnostic native is different to methods of cordova plugin diagnostic


#1

Hi,

I’ve a problem using ionic native diagnostic methods:

getCameraAuthorizationStatus(externalStorage?: boolean): Promise<any>;
requestCameraAuthorization(externalStorage?: boolean): Promise<any>;

Each method receives as parameter the externalStorage: boolean. But by calling the corresponding methods in the cordova plugin, these receive an object:

/**
* Returns the authorisation status for runtime permissions to use the camera.
* Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
* @param {Object} params - (optional) parameters:
*  - {Function} successCallback - function to call on successful request for runtime permissions status.
* This callback function is passed a single string parameter which defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
*  - {Function} errorCallback - function to call on failure to request authorisation status.
*  - {Boolean} externalStorage - (Android only) If true, checks permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission.
*  cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.
*/
Diagnostic.getCameraAuthorizationStatus = function(params){
...
}

/**
* Requests authorisation for runtime permissions to use the camera.
* Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will have no effect as the permissions are already granted at installation time.
* @param {Object} params - (optional) parameters:
*  - {Function} successCallback - function to call on successful request for runtime permissions.
* This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
*  - {Function} errorCallback - function to call on failure to request authorisation.
*  - {Boolean} externalStorage - (Android only) If true, requests permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission.
*  cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.
*/
Diagnostic.requestCameraAuthorization = function(params){
...
}

When I use these methods in my ionic app, it throws the error:

ERROR Error: Uncaught (in promise): TypeError: this.onSuccessAuthorizationStatus is not a function
TypeError: this.onSuccessAuthorizationStatus is not a function
    at Object.successCallback (main.js:61419)
    at onSuccess (diagnostic.js:813)
    at onSuccess (diagnostic.js:334)
    at Object.callbackFromNative (cordova.js:293)
    at processMessage (cordova.js:1119)
    at processMessages (cordova.js:1142)
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (main.js:4622)
    at t.invoke (polyfills.js:3)
    at n.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (main.js:4613)
    at t.invokeTask (polyfills.js:3)
    at n.runTask (polyfills.js:3)
    at Object.successCallback (main.js:61419)
    at onSuccess (diagnostic.js:813)
    at onSuccess (diagnostic.js:334)
    at Object.callbackFromNative (cordova.js:293)
    at processMessage (cordova.js:1119)
    at processMessages (cordova.js:1142)
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (main.js:4622)
    at t.invoke (polyfills.js:3)
    at n.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (main.js:4613)
    at t.invokeTask (polyfills.js:3)
    at n.runTask (polyfills.js:3)
    at d (polyfills.js:3)
    at l (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (main.js:4613)
    at t.invokeTask (polyfills.js:3)
    at n.runTask (polyfills.js:3)
    at a (polyfills.js:3)
    at <anonymous>

This is my:

"dependencies": {
...
        "@ionic-native/diagnostic": "^3.7.0",
...
        "cordova.plugins.diagnostic": "^3.6.2",
...
    }

Regards!


#2

I don’t know what is the problem but you can use direct cordova function until native fixed.

cordova.plugins.diagnostic.getCameraAuthorizationStatus(successCallback, errorCallback, externalStorage)

declare let cordova: any;

@Component({
  selector: 'page-home',
  templateUrl: 'home.component.html'
})
export class HomeComponent implements OnInit {

  constructor() {

  }

   ngOnInit() {
      cordova.plugins.diagnostic.getCameraAuthorizationStatus((status) => {
         if(status === cordova.plugins.diagnostic.permissionStatus.GRANTED){
            console.log("Camera use is authorized");
        }
       }, (error) => {

       }, true)
   }

}

#3

Try updating @ionic-native/diagnostic to 3.10.2. I think PR #1458 addressed your issue.