You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I followed the setup steps perfectly, but on iOS when I kill my app; it's not sending location updates to firebase.
Am I mistaken? Does this not run in the background when I kill my app? I'm assuming it does and doesn't. Like it does run, but my JavaScript listeners don't.
Would a solution be to use the post to server option and update firebase that way?
import { NgZone, Injectable } from '@angular/core';
import BackgroundGeolocation, {
Location,
Subscription,
} from '@transistorsoft/capacitor-background-geolocation';
import { FirebaseService } from './firebase.service';
import { Subject } from 'rxjs';
@Injectable({
providedIn: 'root',
})
/**
* This is the location service for the CURRENT phone user
*/
export class LocationService {
events: any = [];
subscriptions: Subscription[] = [];
lastLocation: Location | null = null;
isListening = false;
private locationUpdateSubject = new Subject<Location>();
public locationUpdate$ = this.locationUpdateSubject.asObservable();
constructor(private firebaseService: FirebaseService) {}
async prepareAndStart() {
try {
this.subscriptions.push(
BackgroundGeolocation.onLocation((location) =>
this.locationReceived(location)
)
);
/// Step 2: Ready the plugin.
await BackgroundGeolocation.ready({
// url: 'localhost:3000', // put a firebase on request function url here
// params: {
// user_id: 1234, // put a firebase user id here so we know who's location is being pinged
// },
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
// Activity Recognition
stopTimeout: 5,
// Application config
debug: false, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_OFF,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
});
BackgroundGeolocation.start().then(() => {
this.isListening = true;
});
} catch (error) {
alert(error);
}
}
/**
* Every time the location is received, we want to store it locally on lastLocation and also in the DB.
* We are using the realtime database here. See storeUser.
* @param location
*/
locationReceived(location: Location) {
this.firebaseService.storeUser(
location.coords.latitude,
location.coords.longitude
);
this.lastLocation = location;
this.locationUpdateSubject.next(location);
}
getCurrentLocation() {
BackgroundGeolocation.getCurrentPosition(
{},
(location) => {
this.locationReceived(location);
},
(error) => {}
);
}
}
The text was updated successfully, but these errors were encountered:
Hello,
I followed the setup steps perfectly, but on iOS when I kill my app; it's not sending location updates to firebase.
Am I mistaken? Does this not run in the background when I kill my app? I'm assuming it does and doesn't. Like it does run, but my JavaScript listeners don't.
Would a solution be to use the post to server option and update firebase that way?
The text was updated successfully, but these errors were encountered: