Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rolinger opened this issue Jan 9, 2025 · 0 comments

Comments

@rolinger
Copy link

rolinger commented Jan 9, 2025

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
        }
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant