dpa99c / cordova-diagnostic-plugin

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

All callbacks return undefined #380

Closed ChrisAelbrecht closed 5 years ago

ChrisAelbrecht commented 5 years ago

I created an Ionic project to convert an existing AngularJS webapp to a hybrid app. Works perfectly.

I added cordova-plugin-geolocation to get the geolocation working, which did, but I saw that the corodova.plugins.diagnostic has better support, so I added that. However, to get that working I had to add to index.html <script src="cordova.js"></script> which wasn't in before.

So, I now try to get the location authorization when the app loads as follows:

$ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins) {
        console.log('Cordova plugins ready');
        if (window.cordova.plugins.diagnostic) {
            console.log('Diagnostic plugin ready');
            window.cordova.plugins.diagnostic.getLocationAuthorizationStatus(evaluateGeolocationAuthorizationStatus, onGeolocationAuthorizationError);
        }
    }
});

When looking in the console I do see Diagnostic plugin ready, but nothing happens. When I run in the chrome console window.cordova.plugins.diagnostic.getLocationAuthorizationStatus(function(status) {console.log('status: ' + status)}, function(error) {console.log (error)}); I get undefined.

When I try the classical window.navigator.geolocation.getCurrentPosition(onSuccess, onError, options) I also get undefined.

When I remove <script src="cordova.js"></script> I don't have access to window.cordova, but now the callback of window.navigator.geolocation.getCurrentPositionworks again.

So, in short: adding <script src="cordova.js"></script> prevents these callbacks.

I already removed and added again the Android platform, but all stays the same. Can anyone help?

Thank you!

Chris

ionic 5.2.2
cordova 9.0.0
cordova-android 8.1.0

my package.json file

{
  "name": "x",
  "version": "0.0.1",
  "description": "x",
  "devDependencies": {
    "@ionic/v1-toolkit": "^1.0.0",
    "gulp": "^3.5.6",
    "gulp-clean-css": "^3.7.0",
    "gulp-exec": "^4.0.0",
    "gulp-rename": "^1.2.0",
    "gulp-sass": "^3.1.0",
    "gulp-xml-transformer": "^3.0.0"
  },
  "dependencies": {
    "cordova-android": "^8.1.0",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.1.2",
    "cordova-plugin-splashscreen": "^5.0.3",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-whitelist": "^1.3.4",
    "cordova.plugins.diagnostic": "^5.0.1"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-geolocation": {},
      "cordova.plugins.diagnostic": {}
    },
    "platforms": [
      "android"
    ]
  }
}
dpa99c commented 5 years ago

This is a support request not a bug report/feature request related to this plugin. Please post it to Stack Overflow or the Ionic help forums.

ChrisAelbrecht commented 5 years ago

https://stackoverflow.com/questions/58588963/adding-cordova-js-prevents-geolocation-or-any-other-callback

ChrisAelbrecht commented 5 years ago

Any help is much appreciated!