Skip to content

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

Description

@rolinger

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
        }
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions