diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.m b/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.m index 6935f7061..acffd8fc9 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalLocation.m @@ -290,12 +290,19 @@ + (void)showLocationSettingsAlertController { }]; } ++ (BOOL)backgroundTaskIsActive { + return fcTask && (fcTask != UIBackgroundTaskInvalid); +} + + (void)requestLocation { onesignal_Log(ONE_S_LL_DEBUG, @"OneSignalLocation Requesting Updated Location"); id clLocationManagerClass = NSClassFromString(@"CLLocationManager"); if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground && [clLocationManagerClass performSelector:@selector(significantLocationChangeMonitoringAvailable)]) { [locationManager performSelector:@selector(startMonitoringSignificantLocationChanges)]; + if ([self backgroundTaskIsActive]) { + [self endTask]; + } } else { [locationManager performSelector:@selector(requestLocation)]; } @@ -345,11 +352,17 @@ - (void)locationManager:(id)manager didUpdateLocations:(NSArray *)locations { [OneSignalLocation sendLocation]; [OneSignalLocation sendAndClearLocationListener:PERMISSION_GRANTED]; + if ([OneSignalLocation backgroundTaskIsActive]) { + [OneSignalLocation endTask]; + } } - (void)locationManager:(id)manager didFailWithError:(NSError *)error { [OneSignal onesignal_Log:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"CLLocationManager did fail with error: %@", error]]; [OneSignalLocation sendAndClearLocationListener:ERROR]; + if ([OneSignalLocation backgroundTaskIsActive]) { + [OneSignalLocation endTask]; + } } + (void)resetSendTimer {