Skip to content

Commit

Permalink
Fix prompting for location permission
Browse files Browse the repository at this point in the history
  • Loading branch information
troy-lamerton authored and jkasten2 committed Apr 4, 2019
1 parent add0227 commit 7fbff43
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions iOS_SDK/OneSignalSDK/Source/OneSignalLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ + (void) internalGetLocation:(bool)prompt {
// Check for location in plist
if (![clLocationManagerClass performSelector:@selector(locationServicesEnabled)])
return;

if ([clLocationManagerClass performSelector:@selector(authorizationStatus)] == 0 && !prompt)
int permissionStatus = [clLocationManagerClass performSelector:@selector(authorizationStatus)];
// return if permission not determined and should not prompt
if (permissionStatus == 0 && !prompt)
return;

locationManager = [[clLocationManagerClass alloc] init];
Expand All @@ -186,15 +187,17 @@ + (void) internalGetLocation:(bool)prompt {
//Location Always requires: Location Background Mode + NSLocationAlwaysUsageDescription
NSArray* backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
NSString* alwaysDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] ?: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"];
if(backgroundModes && [backgroundModes containsObject:@"location"] && alwaysDescription) {
// use background location updates if always permission granted or prompt allowed
if(backgroundModes && [backgroundModes containsObject:@"location"] && alwaysDescription && (permissionStatus == 3 || prompt)) {
[locationManager performSelector:@selector(requestAlwaysAuthorization)];
if (deviceOSVersion >= 9.0) {
[locationManager setValue:@YES forKey:@"allowsBackgroundLocationUpdates"];
}
}

else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"])
[locationManager performSelector:@selector(requestWhenInUseAuthorization)];
else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
if (permissionStatus == 0) [locationManager performSelector:@selector(requestWhenInUseAuthorization)];
}

else onesignal_Log(ONE_S_LL_ERROR, @"Include a privacy NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription in your info.plist to request location permissions.");
}
Expand Down

0 comments on commit 7fbff43

Please sign in to comment.