transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
655 stars 277 forks source link

window.plugins.backgroundgeolocation or window.BAckgroundGeolocation isn't works #653

Closed Trauck closed 6 years ago

Trauck commented 6 years ago

I tryed to put a background geolocation on my app like a sport app. Then i download this plugins and wanna try it on my browser. But this error append : "Uncaught TypeError: Cannot read property 'backgroundGeoLocation' of undefined" on Chrome and "TypeError: window.plugins is undefined[En savoir plus] index.js:229:13" on firefox..

Then i tryed to fix it with using window.Backgroudgeolocation but nothing works. I really don't know what to do..

In addition I looked a lot of forum dealing with this type of problem and nothing works so please do not redirect me.

(Sorry if my statement is not clear, or not very well written)

christocracy commented 6 years ago

The plugin is available at window.BackgroundGeolocation as documented in README.

Show me your:

$ cordova plugins
Trauck commented 6 years ago

Yes, i read that then i wanna change it but it doesn't work.. I can't instal the right version in the bash.

image

christocracy commented 6 years ago

You are using the wrong plugin.

$ cordova plugin remove cordova-plugin-background-geolocation
$ cordova plugin add cordova-background-geolocation-lt
Trauck commented 6 years ago

Oh yes sorry, i didn't see there is a new version of this plugin. I'll try it.

Thank you.

Trauck commented 6 years ago

Well, after doing all the required installations, i end up with the same problem: bgGeo is undefined.

image Said , bgGeo is undefined line 147.

I must have forgotten to put a variable in the right function or not called a necessary script ..

christocracy commented 6 years ago

Remove / re-add platforms

Remove / re-add plugin.

christocracy commented 6 years ago
$ cordova platforms
Trauck commented 6 years ago

Done, but now should i make someting else or i could add the previous code in my map.js (javascript file linked to my html) ? image

christocracy commented 6 years ago

I don't understand your question. I asked you to show me the following information:

$ cordova platforms
Trauck commented 6 years ago

This is my platforms : (sorry my browser didn't refresh).

image

christocracy commented 6 years ago

The plugin is not yet ready for cordova-android@7.0.0

$ cordova platform remove android
$ cordova platform add android@6.4.0
Trauck commented 6 years ago

And it only works on device or we can test it on browser like the last version of background geolocation ?

christocracy commented 6 years ago

The plugin does not exist in browser. The plugin implements native location and motion apis (accelerometer, gyroscope, compass).

The browser does not have these apis. Just like the browser doesn't have a Camera API.

You must test on device or sim.

Trauck commented 6 years ago

So, i am trying on my device and at launch, this message appears: "Licence Validation Failure BackgroundGeolocation is running in evaluation mode."

Is this the key license in the config.xml file. If that's it I do not have an android key, and I'm a student, so this is not a commercial application and I do not intend to pay for a license.

christocracy commented 6 years ago

You cannot use Android without purchasing a license key.

christocracy commented 6 years ago

Android will work only in DEBUG builds, so that you can evaluate the plugin before purchase.

Android will not work in RELEASE builds without purchase.

Trauck commented 6 years ago

The problem here is that I test my application on my phone that is connected to my pc .. So I can not even test without a license. Otherwise, the problem seems solved, I will see what I will do with the android license. Thank you.

christocracy commented 6 years ago

The message "Licence Validation Failure BackgroundGeolocation is running in evaluation mode." is fine.

This means the plugin is running in DEBUG build and is fully operational. It's running in evaluation mode so that you can evaluate the performance of the plugin before purchase.

Trauck commented 6 years ago

And how do you access this evaluation mode? I just use $ cordova run android and the application launches on my phone. (I'm sorry for the time I take you, especially for beginners questions, I'm just starting after some project done)

christocracy commented 6 years ago

Just don't worry about this. If you see Toast message "Licence Validation Failure BackgroundGeolocation is running in evaluation mode.", you're good to do.

Yes, just run your app with.

$ cordova run android
Trauck commented 6 years ago

Yes that's what I'm doing, and just then the message appears.

christocracy commented 6 years ago

IT IS SUPPOSED TO APPEAR.

Trauck commented 6 years ago

Yes I understand that but so I can not test this plugin without license.

Trauck commented 6 years ago

Thank you for all these tips and still sorry for the time used.

christocracy commented 6 years ago

YES YOU CAN.

Just IGNORE the message and pretend you have a license.

Trauck commented 6 years ago

Well when I come to my page map, nothing happens, like when there is an error in the js.

christocracy commented 6 years ago

See Debugging Wiki

Trauck commented 6 years ago

There is a lot of information, but the last one is pretty clear.

image

And i sincerely think that the error comes from the fact that I do not know where to put the part of the code js in my code map.js. And do I call a plugin script in my html page.

christocracy commented 6 years ago

Do not post screenshots of logs. Post the text.

I know nothing of your map.js.

See docs for stopOnTerminate

umasankarm commented 6 years ago

Hi i tried to integrate with in my hybrid mobile app using ReactJS(not react native), i defined plugin in the config.xml as version below

plugin name="cordova-background-geolocation-lt" spec="^2.11.0-beta.1"></plugin

when i tried to run my application it found the below error on console

Uncaught TypeError: Cannot read property 'on' of undefined at Channel.c (myfileName.js:1921) at Channel.fire (cordova.js:846) at cordova.js:231

christocracy commented 6 years ago

@umasankarm

Your Environment

umasankarm commented 6 years ago

Plugin version : i mentioned in config.xml -> name="cordova-background-geolocation-lt" spec="2.10.1" source="npm" Platform : Android OS Version : 5.1.1 Device manufacturer : Lenovo A6020a46 Cordova version : i am doing build by Phonegap cloud through Maven

I changed my code like below

var bgGeo = window.BackgroundGeolocation; to var bgGeo = window.plugins.BackgroundGeolocation;

now i get a error as Uncaught TypeError: Cannot read property 'BackgroundGeolocation' of undefined at Channel.c (xxxxx.js:1921) at Channel.fire (cordova.js:846) at cordova.js:231

and i added a

org.webjars.npm cordova-background-geolocation-lt 2.10.1

in pom.xml and import into my main file as

import BackgroundGeolocation from 'cordova-background-geolocation-lt/2.10.1/cordova-background-geolocation-lt';

still its undefined.

christocracy commented 6 years ago

Using the Plugin

The plugin creates the object window.BackgroundGeolocation. See API Documentation for details

The plugin has nothing to do with window.plugins. It's window.BackgroundGeolocation

in pom.xml and import into my main file as

I know nothing of pom.xml.

import BackgroundGeolocation from 'cordova-background-geolocation-lt/2.10.1/cordova-background-geolocation-lt';

Where did you get the idea to do this??

If you're using typescript:

let bgGeo = (<any>window).BackgroundGeolocation;
umasankarm commented 6 years ago

Even i changed my code based on your suggestion but still i got the error

Uncaught TypeError: Cannot read property 'on' of undefined at Channel.c (xxxx.js:1921) at Channel.fire (cordova.js:846) at cordova.js:231

whether i need to add any key in the variable tag at config.xml file under plugin tag for development mode ? <variable name="LICENSE" value="YOUR_LICENSE_KEY" />

christocracy commented 6 years ago

whether i need to add any key in the variable tag at config.xml file under plugin tag for development mode ?

No. The plugin will work in DEBUG builds without a license. Even if you built for RELEASE, the Javascript API is still available at window.BackgroundGeolocation.

If there is no Javascript API available at window.BackgroundGeolocation, you do not have the plugin installed.

umasankarm commented 6 years ago

ok.. then what may be the problem ? We developed a project with ReactJS and build it through phonegap for android and iOS

christocracy commented 6 years ago

I do not know.

umasankarm commented 6 years ago

We can't use the plugin with ReactJs ? for build hybrid application

christocracy commented 6 years ago

This is a pure Cordova plugin. It doesn't care about what Javascript framework you use.

The plugin installs its Javascript API at window.BackgroundGeolocation.

You're not attempting to use the plugin in the browser, are you? The plugin API is only available on Device or Simulator.

umasankarm commented 6 years ago

actually i installed the apk in mobile and i debugged through Chrome browser by remote device debugging.

christocracy commented 6 years ago

In Javascript console

>bg = window.BackgroundGeolocation
umasankarm commented 6 years ago

bg

christocracy commented 6 years ago

Install cordova-plugin-device and attempt to access it from the Javascript console.

umasankarm commented 6 years ago

in browser ? or in a application ?

christocracy commented 6 years ago

You can't install a Cordova plugin "in the browser".

$ cordova plugin add cordova-plugin-device
umasankarm commented 6 years ago

ok, i am not using cordova CLI, i will do by adding webjars and will back with good results may be. Thank you

christocracy commented 6 years ago

I have never heard of “webjars”.

umasankarm commented 6 years ago

`

org.webjars.npm
<artifactId>cordova-plugin-device</artifactId>
<version>1.1.4</version>

`

i get in the site https://www.webjars.org/

christocracy commented 6 years ago

What makes you think that my plugin is magically available on this “webjars”?