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

Update WSViewController.m #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions phoneClients/ios/GpsTracker/WSViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ - (void)viewDidLoad
currentlyTracking = NO;
timeIntervalInSeconds = 60; // change this to the time interval you want

if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self requestAlwaysAuthorization];
}


BOOL appIDIsSet = [[NSUserDefaults standardUserDefaults] boolForKey:@"appIDIsSet"];
if (!appIDIsSet) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"appIDIsSet"];
Expand Down Expand Up @@ -217,4 +222,30 @@ - (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
}


- (void)requestAlwaysAuthorization
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];

// If the status is denied or only granted for when in use, display an alert
if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusDenied) {
NSString *title;
title = (status == kCLAuthorizationStatusDenied) ? @"Location services are off" : @"Background location is not enabled";
NSString *message = @"To use background location you must turn on 'Always' in the Location Services Settings";

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Settings", nil];
[alertView show];
}
// The user has not enabled any location services. Request background authorization.
else if (status == kCLAuthorizationStatusNotDetermined) {
[locationManager requestAlwaysAuthorization];
}
}



@end