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

ios - plugin does not work after app is terminated #704

Closed Hector52mrs closed 5 years ago

Hector52mrs commented 5 years ago

I am not provide any url to config of plugin but i am using this.bgGeo.getLocations().then((locations)=> {}); method to track. this plugin is worked fine when app is running but after app is terminated plugin does not work. i.e. plugin does not store location when app is not running.

when am i used simulator to test plugin with Freeway Drive then getLocation() method is worked after app is terminated but when i am used real device then app is not worked after app is terminated.

When i test this plugin with real device then i put distanceFilter: 50, stationaryRadius:50 and i am going around 3 km for testing but after app is terminated , plugin does not work.

Your Environment

please see my whole code for better understand.

this.platform.ready().then(() => { this.bgGeo = (<any>window).BackgroundGeolocation; this.onDeviceReady(); });

`onDeviceReady() {

this.bgGeo.on('location', this.onLocation.bind(this));
this.bgGeo.on('motionchange', this.onMotionChange.bind(this));
this.bgGeo.on('activitychange', this.onActivityChange.bind(this));
this.bgGeo.on('geofence', this.onGeofence.bind(this));
this.bgGeo.on('http', this.onHttpSuccess.bind(this), this.onHttpFailure.bind(this));

// BackgroundGeoLocation is highly configurable.
this.bgGeo.ready({
    // Geolocation config
    desiredAccuracy: 0,
    distanceFilter: 50,
    stationaryRadius: 50,
    // Activity Recognition config
    stopTimeout: 5,
    // Application config
    debug: true,  // <-- Debug sounds & notifications.
    reset: true,
    logLevel: this.bgGeo.LOG_LEVEL_VERBOSE,
    stopOnTerminate: false,
    startOnBoot: true,
    method: "POST",
    autoSync: true,
    maxDaysToPersist: 3

}, function(state) {
    // This callback is executed when the plugin is ready to use.
    console.log("BackgroundGeolocation ready: ", state);
    this.bgGeo.start();
});

}`

`
onLocation(location, taskId) { console.log('- location: ', location); if(location.sample === true) {

    this.bgGeo.getLocations().then((locations)=> {
      this.arrLocations = [];
      console.log("stored locations: ", locations);
            for(let i=0; i<locations.length; i++) {
                var millisec = new Date(locations[i].timestamp);
                var milliInDate = moment(millisec).format('YYYY-MM-DDTHH:mm:ss');

                this.arrLocations.push({
                    Lat: locations[i].coords.latitude,
                    Long: locations[i].coords.longitude,
                    Date: milliInDate,
                    BatteryPerc: locations[i].battery.level
                });
            }

            setTimeout(()=> {
                 // push data to server
             },3000);
    }).catch((err)=> {
      console.log('error: ', err);
    });

  }

this.bgGeo.finish(taskId);

} `

Expected Behavior

Actual Behavior

Steps to Reproduce

1. 2. 3. 4.

Context

Debug logs

Hector52mrs commented 5 years ago

hello sir, please update me asap

christocracy commented 5 years ago

See #stopOnTerminate

Yes, your iOS app does terminate. It will reboot after you move by at least 200 metres and resume tracking. It's completely in iOS' hands to reboot your app and depends upon the local network environment and requires Wifi enabled.

Hector52mrs commented 5 years ago

i already enable stopOnTerminate to false and also after i terminated the app i ride the bike around 2 km but plugin does not resume the tracking. Why plugin is not stored the locations after app is terminated ?

Hector52mrs commented 5 years ago

i am calling getLocations () method in onLocation () method

christocracy commented 5 years ago

with debug: true, the plugin will tell you and notify you when iOS reboots your app in the background. If you don't see and hear iOS re-awakening your app, then your app is not rebooting, thus no locations recorded.

The plugin is at the mercy of iOS and your local network environment (and wifi enabled). All you can do is stopOnTerminate: false and keep testing in other directions.

Hector52mrs commented 5 years ago

if i am moving around 2-3 km and after that app also not rebooted then what should i do ?

christocracy commented 5 years ago

I do not know. It it works in the sim, your problem is the network environment (eg: spacing of cell towers, lack of wifi signals).

Hector52mrs commented 5 years ago

no man, i am giving 4g network and network speed is not slow.

christocracy commented 5 years ago

If it works in sim, that's all you can do.

Hector52mrs commented 5 years ago

i tested in both sim and wifi but at both time plugin is not worked after app is terminated.

christocracy commented 5 years ago

See Video

Hector52mrs commented 5 years ago

I already saw your video man, i am not telling that problem is in your plugin but i am telling that your problem is not work in my project and i am just telling you please find how ?

Hector52mrs commented 5 years ago

And i am calling http URL custom not from plugin

Hector52mrs commented 5 years ago

And also i want to ask that, is this plugin store the location when device is offline ?

christocracy commented 5 years ago

is this plugin store the location when device is offline ?

Yes

Hector52mrs commented 5 years ago

Hello Man, onLocation method is also call after app is terminated but only when i am testing in the simulator. But when i am testing the app in real device then onLocation method does not call after app is terminated. and also after app terminated, i moved around 2-3 km but no any get update. Why man ?

christocracy commented 5 years ago

It’s completley up to iOS to reboot your app after termination. If it works in the sim, that’s all you can do. Everything else depends upon your network environment and device settings (eg spacing of cell towers, WiFi enabled on device, “Always” location authorized.)

When I personally test in countries around the world (USA, Canada, Mexico, Dominican Republic, UK, Iceland), it takes about 200 meters movement for app to reboot,

aaronharper123 commented 5 years ago

ok let me check

christocracy commented 5 years ago

Closed for lack of feedback.

yomencity commented 5 years ago

@christocracy What do yo mean " If it works in the sim, that’s all you can do. Everything else depends upon your network environment and device settings (eg spacing of cell towers, WiFi enabled on device, “Always” location authorized.)"? I have same issue. And I can not still solve that problem. and I tested your plugin with real device(IPhone 6) which I can not call someone with. Then in my device background location service doesn't work? because of lack of sim?

yomencity commented 5 years ago

+) Because my device can not service 3G or 4G ( - I bought that for the purpose of testing app at the flea market), I tested your plugin turning on hotspot to use wifi.

christocracy commented 5 years ago

@yomencity I test with iOS devices with no sim all the time (iPhone 6s, iPhone 5). They have no trouble at all with tracking. Obviously they can't upload locations until I return to my office Wifi network.

yomencity commented 5 years ago

Then, what is the problem in my case? I made stopOnTerminate be false already and walked more than 2 miles.

yomencity commented 5 years ago

And I don't have any trouble in android

yomencity commented 5 years ago

@christocracy Would you show me your code especially about setconfig?

christocracy commented 5 years ago

setConfig is irrelevant.

Show me your logs.

yomencity commented 5 years ago

logs which I get with adb logcat?

yomencity commented 5 years ago

In IOS I only get the message "waiting device" after I command adb logcat.

christocracy commented 5 years ago

There’s no such thing as adb logcat with iOS. See wiki Debugging.

yomencity commented 5 years ago

Then, What should I show you? my code?

christocracy commented 5 years ago

Read the wiki Debugging.

yomencity commented 5 years ago

logcat.txt

yomencity commented 5 years ago

Sorry I don't know which part I should show you. It's very looooong

christocracy commented 5 years ago

Why are you sending me Android logs for an iOS issue??

Do you know what “adb” means? Android Development Bridge.

If you can’t figure out the difference between Android logs vs iOS logs, no wonder you have issues.

yomencity commented 5 years ago

Which one you install first? cordova-background-geolocation-lt plugin or platform?

yomencity commented 5 years ago

I showed you the log using IOS console app. ignore the file name

christocracy commented 5 years ago

Your logs are useless. The instructions to fetch plugin logs are in the Wiki Debugging.

I’m ready to give up on you.

yomencity commented 5 years ago

I already read so many times. But I don't know what the problem is. xcode -> window -> device -> openlog. Is this not correct way? you can teach me how to get log about your log. please don't give up.

christocracy commented 5 years ago

It’s all explained In Wiki Debugging. This is your last chance.

yomencity commented 5 years ago

Thanks for your chance. But I want to ask you a question. step1) bgGeo.getLog(function(log) { console.log(log); }); step2 ) When testing at your work-station, you can observe the plugin logs in XCode:

Is this way right?

yomencity commented 5 years ago

knock knock...