Skip to content

Commit

Permalink
Merge pull request #6082 from pec1985/benbahrenburg-TC-4715
Browse files Browse the repository at this point in the history
[TC-4715] iOS Add ability to request Geo Location Permission
  • Loading branch information
cheekiatng committed Sep 16, 2014
2 parents a6609a9 + 0ca07d1 commit ad9eea3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion iphone/Classes/GeolocationModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
@interface GeolocationModule : TiModule<CLLocationManagerDelegate> {
CLLocationManager *locationManager;
CLLocationManager *tempManager; // Our 'fakey' manager for handling certain <=3.2 requests

CLLocationManager *locationPermissionManager; // used for just permissions requests

CLLocationAccuracy accuracy;
CLLocationDistance distance;
CLLocationDegrees heading;
Expand Down
48 changes: 48 additions & 0 deletions iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ -(void)_destroy
{
[self shutdownLocationManager];
RELEASE_TO_NIL(tempManager);
RELEASE_TO_NIL(locationPermissionManager);
RELEASE_TO_NIL(singleHeading);
RELEASE_TO_NIL(singleLocation);
RELEASE_TO_NIL(purpose);
Expand Down Expand Up @@ -806,6 +807,53 @@ -(NSNumber*)AUTHORIZATION_WHEN_IN_USE
return NUMINT(0);
}

-(CLLocationManager*)locationPermissionManager
{
// if we don't have an instance, create it
if (locationPermissionManager == nil) {
locationPermissionManager = [[CLLocationManager alloc] init];
locationPermissionManager.delegate = self;
}
return locationPermissionManager;
}

-(void)requestAuthorization:(id)value
{
if (![TiUtils isIOS8OrGreater]) {
return;
}
ENSURE_SINGLE_ARG(value, NSNumber);

CLAuthorizationStatus requested = [TiUtils intValue: value];
CLAuthorizationStatus currentPermissionLevel = [CLLocationManager authorizationStatus];

if(requested == kCLAuthorizationStatusAuthorizedWhenInUse){
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
if((currentPermissionLevel == kCLAuthorizationStatusAuthorizedAlways) ||
(currentPermissionLevel == kCLAuthorizationStatusAuthorized)) {
NSLog(@"[WARN] cannot change already granted permission from AUTHORIZATION_ALWAYS to AUTHORIZATION_WHEN_IN_USE");
}else{
[[self locationPermissionManager] requestWhenInUseAuthorization];
}
}else{
NSLog(@"[ERROR] the NSLocationWhenInUseUsageDescription key must be defined in your tiapp.xml in order to request this permission");
}
}
if ((requested == kCLAuthorizationStatusAuthorizedAlways) ||
(requested == kCLAuthorizationStatusAuthorized)) {
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
if (currentPermissionLevel == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"[ERROR] cannot change already granted permission from AUTHORIZATION_WHEN_IN_USE to AUTHORIZATION_ALWAYS");
} else {
[[self locationPermissionManager] requestAlwaysAuthorization];
}
[[self locationPermissionManager] requestAlwaysAuthorization];
}else{
NSLog(@"[ERROR] the NSLocationAlwaysUsageDescription key must be defined in your tiapp.xml in order to request this permission");
}
}
}

#pragma mark Internal

-(NSDictionary*)locationDictionary:(CLLocation*)newLocation;
Expand Down

0 comments on commit ad9eea3

Please sign in to comment.