dpatnaik
dpatnaik

Reputation: 188

Meteor apk :Uncaught TypeError: Cannot read property 'diagnostic' of undefined

I am using Cordova diagnostic plugin. i wrote the code like below as mentioned in plugin github readme But i am getting error in terminal while running cordova app as shown below:Uncaught TypeError:Cannot read Property 'diagnostic' of undefined. But it works fine on web.

       if (Meteor.isCordova) {
// check and request microphone access
cordova.plugins.diagnostic.getMicrophoneAuthorizationStatus(function(status) {
    if (status !== "GRANTED") {
      // if we don't have them request em.
      cordova.plugins.diagnostic.requestMicrophoneAuthorization(function(status) {
        //... do something
        return;
      });
    }
}, function() {
  throw new Meteor.error('failed to get permission for microphone');
});

}

Upvotes: 1

Views: 494

Answers (1)

DaveAlden
DaveAlden

Reputation: 30366

I am not waiting for deviceready event to get triggered.

That'll be why it's not working. The JS elements of plugins are loaded dynamically at runtime by Cordova, hence are not guaranteed to be loaded until the deviceready event has fired, which signals the Cordova environment has finished setting up.

In Meteor, you do this using the Meteor.startup() function:

if (Meteor.isCordova) {
    // Wait for deviceready
    Meteor.startup(function () {
        // check and request microphone access
        cordova.plugins.diagnostic.getMicrophoneAuthorizationStatus(function(status) {
            if (status !== "GRANTED") {
              // if we don't have them request em.
              cordova.plugins.diagnostic.requestMicrophoneAuthorization(function(status) {
                //... do something
                return;
              });
            }
        }, function() {
          throw new Meteor.error('failed to get permission for microphone');
        });
    });
}

Upvotes: 1

Related Questions