问题
I am looking for a solution to my problem and I've been searching in the repo issues, stackoverflow and more, without finding a solution :
I installed the background geolocation plugin og phonegap as it is explained here : https://github.com/christocracy/cordova-plugin-background-geolocation. When deviceready event is received, I try to execute your code example in it but I encountered a few problems :
- first,
window.navigator.geolocation
was not found, I had to replace it bynavigator.geolocation
to get the first geolocation call. - then, the window.plugins.backgroundGeoLocation object is not found too, it is always returns null.
I tried with the solution explained here : https://github.com/christocracy/cordova-plugin-background-geolocation/issues/202 (replacing by in the plugins/org.transistorsoft.cordova.background-geolocation/plugins.xml) but without the result is still null.
When I try to console the window.plugins object, it only returns me { insomnia: {} }
.
I am quite confused, I don't know how to get your plugin object in order to get the geolocation working in background when the phone is asleep (I had no problem using the standard gelocation plugin but I need it to run in background in case the user press the sleep button of his phone).
My version of phonegap : 5.1.1-0.29.0
My version of cordova : 5.1.1
Thank you by advance for your answers !
NB : I tried to prevent sleeping mode with the insomnia plugin, in order to let the gps points capture running. It works, unless you press the sleep button of the phone, which is turning everything off until we awake the phone.. If you have any trick to do the job, I'm taking it !
NB2 : It seems to work after a test under Android. I continue to ping an URL while the phone is asleep (after pressing the sleep button). But on my iPhone, the ping stop when I press the sleep button and it restarts to work when I wake the phone.
回答1:
It seems that phonegap new render system doesn't permit to access to mobile native functionalities. In fact I understood that it renders only views (HTML + CSS + JS). Tools as native cordova geolocation are accessible because they use the navigator but we can't use other plugins using native code.
FYI, this is the version of phonegap I used : http://app.phonegap.com/ It seems to be very limited and restrictive, so, I suggest that you use directly cordova if you have this type of needs.
For more details, you can follow the issue I opened on the repo here : https://github.com/christocracy/cordova-plugin-background-geolocation/issues/203
来源:https://stackoverflow.com/questions/31245385/phonegap-background-geolocation-plugin-not-found