apache / apache/cordova-plugin-geolocation

When app is put in background on iOS, watchPosition does not resume when app is brought to foreground.

Open
#289 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
646
Forks
654
PR merge metrics
No merged PRs in 30d

Description

# Bug Report
As the title explains, on iOS if your app has watchPosition enabled and tracking user movement and the user puts your app in the background, later when the app comes back to the foreground watchPosition does not resume. It does auto-resume on Android.

### What is expected to happen?
On iOS, for watchPosition to resume tracking the users position when app is restored to foreground.

### What does actually happen?
watchPosition fails to reactivate

## Information

On Android, wathcPosition automatically restarts. But for iOS I had to add this code in my device.ready() :

```
document.addEventListener("resume", onResume, false);

function onResume() {
// Handle the resume event
if (ionic.Platform.isIOS()) {
// gpsInfo.gpsEnbaled = user had already enabled GPS
// gpsInfo.gpsTrackingEnabled = watchPosition() had already been initiated
// gpsInfo.watchID = current instance of active watchPosition()

if (gpsInfo.gpsEnabled == true && gpsInfo.gpsTrackingEnabled == true) {

// if a previous watchID still exists, then kill it.
if (gpsInfo.watchID != null) {
gpsPositionTracking(0) ; // kill existing watchID if exists
}

// restart watchPosition()
gpsPositionTracking(1) ; // restart positionTracking
}
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the watchPosition lifecycle on iOS, using the foreground/background transition described in the issue and comparing it with Android behavior. Trace the iOS implementation reached by watchPosition and verify the result by confirming that an existing position watch resumes tracking after the app returns to the foreground.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.