@@ -171,8 +171,9 @@ + (void) internalGetLocation:(bool)prompt {
171171 // Check for location in plist
172172 if (![clLocationManagerClass performSelector: @selector (locationServicesEnabled )])
173173 return ;
174-
175- if ([clLocationManagerClass performSelector: @selector (authorizationStatus )] == 0 && !prompt)
174+ int permissionStatus = [clLocationManagerClass performSelector: @selector (authorizationStatus )];
175+ // return if permission not determined and should not prompt
176+ if (permissionStatus == 0 && !prompt)
176177 return ;
177178
178179 locationManager = [[clLocationManagerClass alloc ] init ];
@@ -186,15 +187,17 @@ + (void) internalGetLocation:(bool)prompt {
186187 // Location Always requires: Location Background Mode + NSLocationAlwaysUsageDescription
187188 NSArray * backgroundModes = [[NSBundle mainBundle ] objectForInfoDictionaryKey: @" UIBackgroundModes" ];
188189 NSString * alwaysDescription = [[NSBundle mainBundle ] objectForInfoDictionaryKey: @" NSLocationAlwaysUsageDescription" ] ?: [[NSBundle mainBundle ] objectForInfoDictionaryKey: @" NSLocationAlwaysAndWhenInUseUsageDescription" ];
189- if (backgroundModes && [backgroundModes containsObject: @" location" ] && alwaysDescription) {
190+ // use background location updates if always permission granted or prompt allowed
191+ if (backgroundModes && [backgroundModes containsObject: @" location" ] && alwaysDescription && (permissionStatus == 3 || prompt)) {
190192 [locationManager performSelector: @selector (requestAlwaysAuthorization )];
191193 if (deviceOSVersion >= 9.0 ) {
192194 [locationManager setValue: @YES forKey: @" allowsBackgroundLocationUpdates" ];
193195 }
194196 }
195197
196- else if ([[NSBundle mainBundle ] objectForInfoDictionaryKey: @" NSLocationWhenInUseUsageDescription" ])
197- [locationManager performSelector: @selector (requestWhenInUseAuthorization )];
198+ else if ([[NSBundle mainBundle ] objectForInfoDictionaryKey: @" NSLocationWhenInUseUsageDescription" ]) {
199+ if (permissionStatus == 0 ) [locationManager performSelector: @selector (requestWhenInUseAuthorization )];
200+ }
198201
199202 else onesignal_Log (ONE_S_LL_ERROR, @" Include a privacy NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription in your info.plist to request location permissions." );
200203 }
0 commit comments