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

http request fail in background mode #82

Closed
ikkettuvvoi opened this issue Oct 27, 2022 · 4 comments
Closed

http request fail in background mode #82

ikkettuvvoi opened this issue Oct 27, 2022 · 4 comments

Comments

@ikkettuvvoi
Copy link

I connected the plugin to my application in Ionic 6.

I noticed that the locations on my web server are not arriving in the background after a few minutes.

By doing a thorough investigation I have agreed that the position is processed correctly in the backgound but the HTTP (POST) call is no longer performed

To Reproduce

async configureBackgroundGeolocation() {
    const uuid = await Device.getId();


    BackgroundGeolocation.addWatcher(
      {
        backgroundMessage: "Track attivo in background",
        backgroundTitle: "Track attivo.",
        requestPermissions: true,
        stale: false,
        distanceFilter: 1
      },
      (location, error) => {
        if (error) {
          if (error.code === "NOT_AUTHORIZED") {
            if (window.confirm(
              "This app needs your location, " +
              "but does not have permission.\n\n" +
              "Open settings now?"
            )) {
              BackgroundGeolocation.openSettings();
            }
          }
          return console.error(error);
        }

        console.log('gillo gps: ', location);

        try {
          let url = environment.api + "/mappa/gps";
          this.http.post(url, { debug: 0, location: location, seriale: uuid }).subscribe((res: any) => {
            console.log('gillo post gps', res);
          },
			(error) => {
			  console.log("gillo error (**) ", error)
			});
        } catch (err) {
          console.log("gillo error (*) ", err)
        }
        return location;
      }
    ).then(function after_the_watcher_has_been_added(watcher_id) {

    });
  }
  • Device: Oppo
  • OS: Android 11
@ikkettuvvoi
Copy link
Author

I apologize, I forgot in a hurry to say thank you.

@diachedelic
Copy link
Collaborator

See #14.

@diachedelic
Copy link
Collaborator

In short, you must use Capacitor's HTTP plugin to send HTTP requests in the background.

@ikkettuvvoi
Copy link
Author

perfect! 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