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

End background task after receiving location #1049

Merged
merged 1 commit into from
Feb 15, 2022
Merged
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
13 changes: 13 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OneSignalLocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}
Expand Down Expand Up @@ -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 {
Expand Down