cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
265 stars 316 forks source link

initialize() is resolving to failure before permitting or denying the permission popup #141

Open ghost opened 8 years ago

ghost commented 8 years ago

using:

<plugin name="cordova-plugin-geofence" spec="0.6.0" />

iphone 6s, both simulator and hardware

Simply executing this in a console:

window.geofence.initialize().then(function () {
    console.log("Successful initialization");
}, function (error) {
    console.log("Error", error);
});

Causes what you see here: image

Interestingly, re-executing initialize later seems to work as expected (depending on if perms are allowed or denied). So, it only seems to have this issue the first time.

sdvg commented 8 years ago

I have the same problem. Did you find a workaround for this, @josh-m-sharpe?

ghost commented 8 years ago

No. I'm using this though, and it mostly seems to work the first time a user encounters it. Obviously delayed.

var initialied = false;
function init(){
  window.geofence.initialize().then(function(){
    initialized = true
  })
}

init();  // pops the permission, but because of the bug can't wait, also 'initialized' is going to be false here

setTimeout(function(){
  init();  // if the user gave permission and if it was done in < 15s, then the var initialized will be set to true here
  setTimeout(function(){
    if(initialized){
      // ok, do stuff
    }
  }, 1000);  // arbitrary 1 second in case the hardware is slow or something.
}, 15000);  // probably long enough for the user to have cleared the dialog
keithmattix commented 8 years ago

Where are we on this? I still am encountering the same issue

craze3 commented 8 years ago

I'm having the same issue. Has anybody found a fix?

marvi14 commented 7 years ago

Hey guys! I was facing the same issue, as I also using another location service, so probably in your .plist file you have 2 location permissions. The use when the app runs and the always permission. Just remove from .plist the "When app run" and just leave the always permission.

That worked for me!

josh-m-sharpe commented 7 years ago

@tsubik any change you could take a look at this? maybe there's an easy fix?