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

Optimizing Redundant Location Updates When Using startUpdatingLocation and requestLocation Together #426

Open
Parkjju opened this issue Jan 8, 2025 · 0 comments

Comments

@Parkjju
Copy link

Parkjju commented Jan 8, 2025

Summary

I observed when using the Radar iOS SDK, both startUpdatingLocation and a periodic requestLocation may trigger location updates simultaneously under certain configurations. While this behavior might be intentional for specific use cases, it could lead to redundant location updates, potentially impacting efficiency or battery performance in scenarios where both methods are active.

Code to reproduce

- (void)startUpdates:(int)interval blueBar:(BOOL)blueBar {
    if (!self.started || interval != self.startedInterval) {
        [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(shutDown) object:nil];

        if (self.timer) {
            [self.timer invalidate];
        }

        // Periodic location request
        self.timer = [NSTimer scheduledTimerWithTimeInterval:interval
                                                     repeats:YES
                                                       block:^(NSTimer *_Nonnull timer) {
                                                           [self requestLocation];
                                                       }];

        // Continuous location updates
        if (blueBar && interval <= 5) {
            [self.locationManager startUpdatingLocation];
        } else {
            [self.locationManager stopUpdatingLocation];
        }

        self.started = YES;
        self.startedInterval = interval;
    }
}

Steps to reproduce

  1. Configure the SDK to call both startUpdatingLocation and requestLocation in the same session.
  2. Set interval to 5 or lower and enable blueBar.
  3. Observe didUpdateLocations being called multiple times within a short period due to overlapping location requests.

OS version

iOS 16.0 and above (confirmed on iOS 16.5 and iOS 17.0).

SDK installation method

CocoaPods

SDK version

3.4.1

Other information

I understand that the simultaneous usage of startUpdatingLocation and requestLocation could be intentional for some use cases. However, in scenarios where efficiency and battery usage are critical, avoiding redundant location updates might improve overall performance.

Would it be possible to:

  1. Automatically manage the overlap between startUpdatingLocation and requestLocation calls?
  2. Provide an additional configuration option to toggle between continuous and periodic location requests?

This is more of a suggestion to explore potential enhancements rather than a bug report. I highly appreciate the work that has gone into the SDK and look forward to any insights or recommendations you may have.

@Parkjju Parkjju changed the title Optimize Redundant Location Updates When Using startUpdatingLocation and requestLocation Together Optimizing Redundant Location Updates When Using startUpdatingLocation and requestLocation Together Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant