Skip to content
This repository was archived by the owner on Oct 8, 2023. It is now read-only.

Commit 1da803c

Browse files
authored
Merge pull request #68 from Microsoft/a-hakhal/check-gps
Add check to make sure location services are switched ON
2 parents fcdc575 + 90db033 commit 1da803c

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

MobileClient/src/pages/home/home.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { Component, NgZone, ViewChild, ElementRef } from '@angular/core';
5-
import { NavController, ModalController, Platform } from 'ionic-angular';
5+
import { NavController, ModalController, Platform, ToastController } from 'ionic-angular';
66
import { Network } from 'ionic-native';
77

88
import { Logger } from 'angular2-logger/core';
@@ -44,7 +44,8 @@ export class HomePage {
4444
private backgroundTrackerService: BackgroundTrackerService,
4545
private mapHostService: MapHostService,
4646
public modalCtrl: ModalController,
47-
private settingsSrvc: SettingsService) {
47+
private settingsSrvc: SettingsService,
48+
private toastController: ToastController) {
4849

4950
this.onDevice = this.platform.is('cordova');
5051
this.platform.ready().then(() => {
@@ -82,7 +83,15 @@ export class HomePage {
8283
}
8384

8485
continueInitialization() {
85-
this.backgroundTrackerService.startTracking();
86+
this.backgroundTrackerService.startTracking().then(() => {
87+
if(!this.backgroundTrackerService.isTracking){
88+
this.toastController.create({
89+
message: 'Location Services is disabled.\n Please enable it to continue.',
90+
duration: 5000,
91+
position: 'middle'
92+
}).present();
93+
}
94+
});
8695

8796
this.mapHostInitialized = true;
8897
this.mapHostService.initialize(this.mapElement.nativeElement);

MobileClient/src/pages/settings/settings.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,23 @@ export class SettingsPage {
6262
}
6363

6464
startService() {
65-
this.backgroundTrackerService.startTracking();
66-
67-
this.toastController.create({
68-
message: 'Starting tracking service',
69-
duration: 3000,
70-
position: 'top'
71-
}).present();
72-
73-
this.trackingServiceRunning = this.backgroundTrackerService.isTracking;
65+
this.backgroundTrackerService.startTracking().then((values) => {
66+
this.trackingServiceRunning = this.backgroundTrackerService.isTracking;
67+
if(!this.trackingServiceRunning){
68+
this.toastController.create({
69+
message: 'Location Services is disabled.\n Please enable it to continue.',
70+
duration: 5000,
71+
position: 'middle',
72+
}).present();
73+
}
74+
else{
75+
this.toastController.create({
76+
message: 'Starting tracking service',
77+
duration: 3000,
78+
position: 'top'
79+
}).present();
80+
}
81+
});
7482
}
7583

7684
stopService() {

MobileClient/src/providers/background-tracker-service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export class BackgroundTrackerService {
5757
return this.startPromise;
5858
}
5959

60+
let locationPromise = new Promise(function(resolve) {
61+
backgroundGeolocation.isLocationEnabled(function (locationEnabled) {
62+
resolve(locationEnabled)
63+
}, function (error) {
64+
resolve(false)
65+
});
66+
});
6067
this.isTracking = true;
6168

6269
let startFinished;
@@ -68,13 +75,21 @@ export class BackgroundTrackerService {
6875
let settingsPromise = this.settingsService.get(Settings.BackgroundOptions);
6976
let tokenPromise = this.settingsService.get(Settings.SecurityToken);
7077

71-
let allPromises = Promise.all([urlPromise, settingsPromise, tokenPromise]);
78+
let allPromises = Promise.all([urlPromise, settingsPromise, tokenPromise, locationPromise]);
7279

7380
allPromises.then((values) => {
74-
81+
7582
let trackingUrl = values[0];
7683
let bgOptions = values[1];
7784
let token = values[2];
85+
let locationStatus = values[3];
86+
87+
if(!locationStatus){
88+
this.isTracking = false;
89+
this.logger.info('[INFO] BackgroundGeolocation services diabled');
90+
}else{
91+
this.logger.info('[INFO] BackgroundGeolocation services enabled');
92+
}
7893

7994
if (!bgOptions) {
8095
this.logger.info('no bgOptions settings');

0 commit comments

Comments
 (0)