NathanaelA / nativescript-permissions

Wraps up the entire Android 6 permissions system in a easy to use plugin.
MIT License
46 stars 22 forks source link

Promises is undefined #4

Closed Gp2mv3 closed 8 years ago

Gp2mv3 commented 8 years ago

Hi, I'm trying to use this plugin and got the following error:

JS: ORIGINAL EXCEPTION: TypeError: Cannot read property 'failed' of undefined
JS: ORIGINAL STACKTRACE:
JS: TypeError: Cannot read property 'failed' of undefined
JS:     at Object.callback (/data/data/org.nativescript.sParks/files/app/tns_modules/nativescript-permissions/permissions.js:49:11)
JS:     at AndroidApplication.Observable.notify (/data/data/org.nativescript.sParks/files/app/tns_modules/data/observable/observable.js:155:23)
JS:     at NativeScriptActivity.onRequestPermissionsResult (/data/data/org.nativescript.sParks/files/app/tns_modules/ui/frame/frame.js:662:29)
JS:     at enableLocationRequestCore (/data/data/org.nativescript.sParks/files/app/tns_modules/nativescript-geolocation/nativescript-geolocation.js:224:51)
JS:     at Object.enableLocationRequest (/data/data/org.nativescript.sParks/files/app/tns_modules/nativescript-geolocation/nativescript-geolocation.js:145:5)
JS:     at AppComponent.enableLocation (/data/data/org.nativescript.sParks/files/app/app.component.js:80:25)
JS:     at AppComponent.onMapReady (/data/data/org.nativescript.sParks/files/app/app.component.js:59:14)
JS:     at DebugAppView._View_AppComponent0._handle_mapReady_2_0 (AppComponent.template.js:605:28)
JS:     at Object.<anonymous> (/data/data/org.nativescript.sParks/files/app/tns_modules/@angular/core/src/linker/view.js:316:24)
JS:     at ZoneDelegate.invoke (/data/data/org.nativescript.sParks/files/app/tns_modules/zone.js/dist/zone-node.js:281:29)
JS: ERROR CONTEXT:
JS: [object Object]

The line 49 is using promises which seems to be undefined. Here is the incriminated function:

application.android.on(application.AndroidApplication.activityRequestPermissionsEvent, function(args) {

  // get current promise set
  var promises = pendingPromises[args.requestCode];

  // Delete it
  delete pendingPromises[args.requestCode];

  // Check the status of the permission
  if (args.grantResults.length > 0) {
    if (args.grantResults[0] === android.content.pm.PackageManager.PERMISSION_GRANTED) {
      promises.granted();
      return;
    }
  }
  promises.failed();

});

Why is promises undefined ? I'm using the plugin exactly as the README suggests it.

NathanaelA commented 8 years ago
  1. Can you tell me which version of Android and on what device you are running it?
  2. Can you tell me what plugins you are using?
  3. Any chance you can share the code you are using to call my promises library?

I can think of two reasons for this to occur;

Both of them are fairly easy to ignore. ;-) So I'll get an update shortly.

NathanaelA commented 8 years ago

This issue is fixed in v1.1.0.