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 not updating when entering again WiFi zone #334

Closed leandromerli closed 6 years ago

leandromerli commented 7 years ago

Your Environment

{ activityRecognitionInterval = 10000; activityType = Other; autoSync = 1; autoSyncThreshold = 0; batchSync = 0; debug = 1; desiredAccuracy = 10; desiredOdometerAccuracy = 100; disableElasticity = 0; disableMotionActivityUpdates = 0; disableStopDetection = 0; distanceFilter = 10; enabled = 0; extras = { }; geofenceInitialTriggerEntry = 1; geofenceProximityRadius = 1000; geofenceTemplate = ""; headers = { }; heartbeatInterval = 60; httpRootProperty = location; isHeartbeatEnabled = 0; isMoving = 0; locationAuthorizationAlert = { cancelButton = Cancel; instructions = "To use background location, you must enable '{locationAuthorizationRequest}' in the Location Services settings"; settingsButton = Settings; titleWhenNotEnabled = "Background location is not enabled"; titleWhenOff = "Location services are off"; }; locationAuthorizationRequest = Always; locationTemplate = ""; locationTimeout = 60; logLevel = 5; logMaxDays = 7; maxBatchSize = "-1"; maxDaysToPersist = 1; maxRecordsToPersist = "-1"; method = POST; minimumActivityRecognitionConfidence = 70; odometer = 0; params = { }; pausesLocationUpdatesAutomatically = 1; preventSuspend = 0; schedule = ( ); schedulerEnabled = 0; startOnBoot = 1; stationaryRadius = 25; stopAfterElapsedMinutes = "-1"; stopDetectionDelay = 0; stopOnTerminate = 0; stopTimeout = 5; trackingMode = 1; url = "https://myserver/api/locationpush"; useSignificantChangesOnly = 0; }

Expected Behavior

I'm in wifi zone.. close the app (so it's in background).. go out off the wifi zone.. then return.. I never open the app again... I expect updates to my server when the background plugin detects that I have internet again

Actual Behavior

In android it connects to wifi and push changes to server In Iphone I have to open my app so I can get updates (when the app is in background (closed) it doesn't)

Steps to Reproduce

  1. Open the app with WiFi 2.Close the app 3.Leave the WiFi and walk
  2. Re enter wi fi after the walk

Context

Get last location

Debug logs

I leave wifi zone at 10:27 am and reenter at 10:47 am

ios logs.zip

christocracy commented 7 years ago

I'm about to push a new release 1.7.0 which may solve this for iOS.

leandromerli commented 7 years ago

Thanks for your quick response.. When do you plan to push the release?

christocracy commented 7 years ago

Probably today.

christocracy commented 7 years ago

Merged latest to master. Try installing from master. It's not yet released to npm.

https://github.com/transistorsoft/cordova-background-geolocation-lt/pull/335

leandromerli commented 7 years ago

I tested.. seems not to work.. the strange thing is that when I turn on my app.. only sent to server the last location.. may be the background is not saving the data to the internal database? I go out more than 1km

christocracy commented 7 years ago

Show me plugin logs

christocracy commented 7 years ago

You know you have to move typically ~200 meters before iOS starts tracking?

leandromerli commented 7 years ago

Yes I was travelling in bus

test ios 2.7 in bus.zip

christocracy commented 7 years ago

It has nothing to do with sync. The plugin is not detecting the device is moving so it not recording any location to sync.

The plugin is going to tell exactly when it's tracking with sound FX and local notifications. If you don't hear the plugin making sound FX / posting local notifications, it's not tracking.

leandromerli commented 7 years ago

Yes, I have a sim.. I have done test with the cellular provider on and it works.. The problem seems to happen when I don't have internet when traveling I will try with desiredAccurancy in 0

christocracy commented 7 years ago

I don't know how far you're travelling but try going in different directions and keep going until you hear the plugin tracking.

Make sure to enable [x] Audio background mode so the plugin can play debug sounds while in background.

christocracy commented 7 years ago

The problem seems to happen when I don't have internet when traveling

What do you mean by this? Don't have internet? You're not disabling any settings on your device, are you?

leandromerli commented 7 years ago

No.. I mean that I don't have the cellular provider on when traveling.. so I go out about 1km then return (1km back) to the WiFi zone

christocracy commented 7 years ago

How are you turning off this "cellular provider"?

leandromerli commented 7 years ago

I go to the settings in iphone and go to cellular.. and turn off "cellular data". This disable the internet by cellular. Not for wifi that continues to work

christocracy commented 7 years ago

You must not disable cellular. iOS geofences requires cellular data to work. The plugin uses a geofence exit event to determine when it's moving.

leandromerli commented 7 years ago

By cellular data I mean the paid service by the carrier.. some users of our app doesn't has this enabled.. only getting internet via WiFi.. Do you mean that if a user doesn't has internet through the carrier it will not record updates?

christocracy commented 7 years ago

No it should work but your method of simulating that is not how to do it.

Remove your SIM card if you want to see if it works without data.

leandromerli commented 7 years ago

I tested in simulator and when my app is close I change the simulator location and it saves to internal database of your plugin. (I see the notification). That feature works in simulator, great.

Then I do this: 1) Switch off wifi 2) simulate a change location 3) Wait a minute 4) Enable again the wifi 5) Wait and change again the location 6) See the servers logs and it arrives two location records

So.. the problem seems that the plugin doesn't detect the network change.

I see the plugin code (not a ios developer expert sorry if I'm wrong) and it doesn't use the Reachability class, Do you detect the network change in other way?

christocracy commented 7 years ago

Yes the plugin does use Reachability. Yes the plugin does accurately detect network changes. No, testing this in the simulator isn't the best way to do this. Are you watching the plugin logs? The plugin is logging network changes.

christocracy commented 7 years ago

If you watch the logs from the plugin in XCode:

Airplane mode ON:

🔵-[TSHttpService init]_block_invoke Network: No Connection | Flags: -- -------

Airplane mode OFF:

🔵-[TSHttpService init]_block_invoke Network: WiFi | Flags: -R -------

Wifi OFF

🔵-[TSHttpService init]_block_invoke Network: Cellular | Flags: WR -t-----
leandromerli commented 7 years ago

Thanks Chris.. may be I have to test in long distance (so It can record some location change.. in short distance (about 1km) seems that Iphone doesn't trigger any event)

I tried the in the phone switching on and off the Wifi and I see the logs you say (great).. When do you detect the WiFi ON do you try to push the records of the database to server?

christocracy commented 7 years ago

In the latest version (2.7.0), the plugin tells its HTTP service to flush records whenever a any network connection is detected.

leandromerli commented 7 years ago

We have been testing the plugin in IOS and seems not to update to server in the scenario I will describe next.

We have tested the 2.7 and the last release 2.7.1 of your plugin.

Our question is if you have tested this scenario and if you are aware de any bug?

Enviroment

Plugin version: 2.7.1 Platform: iOS OS version: 10.3.1 Device manufacturer / model: Iphone 5S Cordova version (cordova -v): 7.0.0 Cordova platform version (cordova platform ls): ios 4.4.0 Plugin config

{
"isMoving": false,
"enabled": true,
"odometer": 90759.2,
"schedulerEnabled": false,
"trackingMode": "location",
"distanceFilter": 1000,
"desiredAccuracy": 1000,
"desiredOdometerAccuracy": 100,
"locationUpdateInterval": 1000,
"fastestLocationUpdateInterval": 5000,
"locationTimeout": 60,
"deferTime": 0,
"disableElasticity": false,
"activityRecognitionInterval": 10000,
"minimumActivityRecognitionConfidence": 75,
"triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
"disableStopDetection": false,
"stationaryRadius": 1000,
"stopTimeout": 5,
"url": "https://server/location",
"method": "POST",
"autoSync": true,
"autoSyncThreshold": 0,
"batchSync": false,
"maxBatchSize": -1,
"params": {},
"headers": {
},
"extras": {},
"httpRootProperty": "location",
"locationTemplate": "",
"geofenceTemplate": "",
"persist": true,
"maxDaysToPersist": 1,
"maxRecordsToPersist": -1,
"locationsOrderDirection": "ASC",
"geofenceProximityRadius": 1000,
"geofenceInitialTriggerEntry": true,
"stopOnTerminate": false,
"startOnBoot": true,
"heartbeatInterval": -1,
"foregroundService": false,
"notificationTitle": "",
"notificationText": "Location Service activated",
"notificationColor": "",
"notificationIcon": "",
"forceReloadOnLocationChange": false,
"forceReloadOnMotionChange": false,
"forceReloadOnGeofence": false,
"forceReloadOnBoot": false,
"forceReloadOnHeartbeat": false,
"forceReloadOnSchedule": false,
"stopAfterElapsedMinutes": 0,
"schedule": [],
"configureUrl": "",
"configureInterval": -1,
"debug": false,
"logLevel": 5,
"logMaxDays": 3
}

Expected Behavior

Every time the device connect to WiFi we expect to push all record location change stored

Actual Behavior

Not updating to server when connection to WiFi

Steps to Reproduce

1)Being in a WiFi zone open our app 2)We receive an update to server 3)Close our app 4)It’s in background: we see the icon in the tray of our iPhone) 5)We go out to another location (5.5 km) 6)We enter a WiFi zone again 7)See the servers logs and no updates are visible 8)Open our app 9)We see posts to server with two or three location records

The location records show us that the plugin is recording the location changes, but It doesn’t update to server when it detects a Network change.

Context

Receive location updates to our server

christocracy commented 7 years ago

The plugin will only receive a connection-change event when the Connection type changes, eg:

Are you observing the corresponding logs?

leandromerli commented 7 years ago

I can't see the logs because when I connect the device the xcode doesn't show me anything (only when I restart the app).. The problem is that the app is close.. so the plugin is in background

christocracy commented 7 years ago

See #getLog / #emailLog methods in docs. The plugin stores 5 days worth of logs (by default)

leandromerli commented 7 years ago

Chris:

I made this test:

TEST 1) Open the app in a wifi zone (I get updates in server) 2) Hide the app (In debug mode.. so I can see the internal updates notifications) 1)Go out 2) Then in the middle of the walk ..force close the app (I can see the geo location icon in the iphone tray so the plugin is active) 3) Arrive to WiFi zone 4) See that the app didn't push anything (wait) 5) open the app with the debugger 6) I see like 30 push of the stored locations

Go out: 17:00 Go in WiFi: 17:11 Open the app: 17:27:13 Server log time -5 hours

WiFi2WiFi -hiden app then close it.zip

christocracy commented 7 years ago
christocracy commented 7 years ago

I don't think what you're hoping to do here is going to work.

Whenever the plugin records any location with autoSync: true, it checks to see if it has a network connection. If so, it will attempt to POST

The plugin will attempt to upload queued locations in the following events:

If you walk into your "wifi zone" and stop for stopTimeout minutes (according to your config, that would be 5 minutes), the plugin is going to record its motionchange position and change to "stationary" state. Since the plugin attempts to POST every recorded location, you should find the plugin will sync at your wifi zone after no later than stopTimeout minutes. This is exactly what happens when I go out for a field-test and return to my office (my "wifi zone").

leandromerli commented 7 years ago

May be what happen is this.. When I close the app.. I think IOS goes to a mode that only sent relative long distance changes.

At this point I don't see any new notification in the rest of the walk (may be it is just because my app is close so it can't create new notifications?)

I continue to walk and get into my wifi zone.. I don't see any updates to the server and any new notification. (Today I wait all night, I didn't open my app yet)

May be at this point: Could be that the background fetch event is not fired because my app is close? OR if it works.. may be it couldn't detect my network change for some reason.

Because I see in my walk that locations are stored (so there are data in)

Yesterday you couldn't see the Network changes logs.. and that's the issue... In the close mode of the app.. It never detects the network change.

Thanks Chris for your time.

christocracy commented 7 years ago

When user terminates an iOS app, your app does actually terminate.

However, iOS does not terminate geofence listeners. Since the plugin is always listening to a geofence around the last-known position, iOS will reboot your app in the background when the device moves beyond that "stationary geofence".

In the following image, imagine the user terminate the app at "big red dot" at bottom right.

The user continues walking north-west. After about 200 meters, iOS detects the device has exited the "stationary geofence" and boots your app in the background. The plugin changes to "moving" state, turns on location-services and begins aggressively tracking. Your app is now completely alive in the background.

Have you read the Philosophy of Operation

leandromerli commented 7 years ago

Yes.. I understand that.. but may be when I walk in the wifi zone.. in that moment the location event is never fired (because could be fired few meters ago, I don't leave the last geofence)..

so If the phone is still it never updates to server.

christocracy commented 7 years ago

When the device is still for stopTimeout minutes, the plugin will change state to "stationary" and record the motionchange location.

Every time a location is recorded, the plugin attempts to flush all queued locations.

leandromerli commented 7 years ago

So probably in that case.. if the phone remains still it will not flush to server

christocracy commented 7 years ago

If the phone remains still for stopTimeout minutes, the motionchange location will be requested and http flush will occur