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

[Help Wanted]: iOS app doesn't restart for background location #309

Open
2 of 3 tasks
stib opened this issue Feb 19, 2025 · 10 comments
Open
2 of 3 tasks

[Help Wanted]: iOS app doesn't restart for background location #309

stib opened this issue Feb 19, 2025 · 10 comments

Comments

@stib
Copy link

stib commented Feb 19, 2025

Required Reading

  • Confirmed

Plugin Version

capacitor-background-geolocation 6.1.4 capacitor-background-fetch 6.0.1

Mobile operating-system(s)

  • iOS
  • Android

What do you require assistance about?

I have the App running in iOS simulator on Mac and simulating a drive. When the App is in foreground or put in background the location updates are recorded successfully. However when the App is closed the location updates stop.

Expected Behavior:
After stationaryRadius is crossed the App should restart and start sending location

Actual Behavior:
The App doesn't restart after terminated, even after waiting for a while. If the App is restarted manually then the updated location shows again, far in excess of the 100 meters specified in stationaryRadius

Ionic info
Ionic:

Ionic CLI : 7.1.1 (/Users/userx/.nvm/versions/node/v20.2.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 6.7.5
@angular-devkit/build-angular : 16.2.16
@angular-devkit/schematics : 16.2.16
@angular/cli : 16.2.16
@ionic/angular-toolkit : 12.1.1

Capacitor:

Capacitor CLI : 6.2.0
@capacitor/android : 6.2.0
@capacitor/core : 6.2.0
@capacitor/ios : 6.2.0

Cordova:

Cordova CLI : 12.0.0 ([email protected])
Cordova Platforms : android 9.1.0, browser 6.0.0, ios 6.2.0
Cordova Plugins : cordova-plugin-ionic-webview 4.2.1, (and 3 other plugins)

Utility:

cordova-res : 0.15.4
native-run : 2.0.1

System:

ios-sim : 8.0.2
NodeJS : v20.2.0 (/Users/userx/.nvm/versions/node/v20.2.0/bin/node)
npm : 9.6.6
OS : macOS Unknown
Xcode : Xcode 16.0 Build version 16A242d

Other Info
It shouldn't matter but I am using iOS 17.5 on emulators - tried for iPhone 15 Pro Max and 13 Pro
App permission is set to Always

Thanks,
Sanjay.

[Optional] Plugin Code and/or Config

# Relevant part of config included
stopOnTerminate: false, 
stationaryRadius: 100,

[Optional] Relevant log output

@christocracy
Copy link
Member

  • configure plugin with debug: true
  • launch your app in Simulator
  • simulate location with “Freeway Drive”

@stib
Copy link
Author

stib commented Feb 20, 2025

Since the log is lengthy instead of pasting it here I created a Google doc and captured it here - has view permission

Steps:

  1. Set debug to true
  2. Set log to Verbose
  3. Compiled and launched in simulator with "Freeway Drive"
  4. Locations are updating
  5. Put App in background
  6. Locations are updating
  7. Closed the App (Log terminates)

Please let me know if I can provide any additional info.

Thanks.

@christocracy
Copy link
Member

Yes, when you terminate an iOS app, the OS completely removes your app from memory. Everything stops, including the logs.

You need to wait about 10s, while the simulator continues along the “freeway drive” route. Your app will come alive again after about 10s (witnessed by the debug notifications). As demonstrated in the following video:

https://youtu.be/aR6r8qV1TI8?si=js-FT6qqT7bc2Y4m

@christocracy
Copy link
Member

Also, you need to ensure your app always calls .ready(config) each and every time your app launches, even if launched automatically by the OS in the background.

@stib
Copy link
Author

stib commented Feb 20, 2025

Thanks Chris. I have waited for several minutes actually, in my multiple tests, but the App does not restart. Upon manually restarting it will show a big location change to the new location, several miles away, much farther than the 100 meters in stationaryRadius.

The App does call the ready function when it restarts which is why upon manual restart it starts sending location changes right away.

Thank you for sharing the demo link Chris - very well put together. As demonstrated in the video, that is what I expect to happen, for the app to restart after stationaryradius is crossed. But that is what doesn't seem to be happening. Not sure why that is the case.

@christocracy
Copy link
Member

It works as-expected for me using the /example/react app in this repo.

capacitor-stop-on-terminate.mp4

@stib
Copy link
Author

stib commented Feb 20, 2025

Thanks Chris. I will try to run your Angular example code as that's what I am using. It should work there and help confirm the issue with my App.

@stib
Copy link
Author

stib commented Feb 24, 2025

Quick update on this.

I cloned the repository and since I am on Capacitor 6 (not moved to 7 yet) I did a checkout
git checkout e79040b to work with the version 6. I am running into errors after npm install and npm run build. Will post here once that is resolved or if I need help there. Thanks.

@stib
Copy link
Author

stib commented Mar 3, 2025

@christocracy sorry for the delay - finally got back to it while I am still traveling.

I did a clean clone and followed the instructions in the Readme file under example/angular. Steps followed -

  1. npm install at the top level
  2. npm run build at the top level
  3. go to example/angular
  4. npm install there
  5. npm run build there - got a bunch of errors about google namespace missing (examples below)

I added the GOOGLE_MAP_API_KEY to the environment.ts file to see if that helps address

npm run build again - still get the google namespace errors as below

Error: node_modules/@capacitor/google-maps/dist/typings/definitions.d.ts:43:34 - error TS2503: Cannot find namespace 'google'.

43 export interface Polygon extends google.maps.PolygonOptions {
                                    ~~~~~~


Error: node_modules/@capacitor/google-maps/dist/typings/definitions.d.ts:64:33 - error TS2503: Cannot find namespace 'google'.

64 export interface Circle extends google.maps.CircleOptions {

Ionic Info output is below

Ionic:

   Ionic CLI                     : 7.2.0 (/Users/usex/.nvm/versions/node/v22.11.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 7.8.6
   @angular-devkit/build-angular : 16.2.16
   @angular-devkit/schematics    : 16.2.16
   @angular/cli                  : 16.2.16
   @ionic/angular-toolkit        : 9.0.0

Capacitor:

   Capacitor CLI      : 7.0.1
   @capacitor/android : 7.0.1
   @capacitor/core    : 7.0.1
   @capacitor/ios     : 7.0.1

Utility:

   cordova-res : not installed globally
   native-run  : 2.0.1

System:

   NodeJS : v22.11.0 (/Users/userx/.nvm/versions/node/v22.11.0/bin/node)
   npm    : 10.9.0
   OS     : macOS Unknown

Unless I am missing something I followed the instructions in the Readme. Please let me know what I may be missing here or if I can provide additional info to help debug the demo app.

Thanks,
Sanjay.

@stib
Copy link
Author

stib commented Mar 6, 2025

@christocracy any thoughts on the issue above in running the example code as is, following the steps outlined? Please let me know if I am missing something obvious here. Thanks.

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

2 participants