Skip to content

Commit

Permalink
Change which request types are used to determine maximum desired accu…
Browse files Browse the repository at this point in the history
…racy

- Only look at Single and Subscription type location requests when determining the maximum desired accuracy
- Rename the "pending" location request methods to "active"
  • Loading branch information
Tyler Fox authored and Tyler Fox committed Sep 3, 2015
1 parent be2dcee commit 103614d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions LocationManager/INTULocationManager/INTULocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ - (void)addLocationRequest:(INTULocationRequest *)locationRequest
{
INTULocationAccuracy maximumDesiredAccuracy = INTULocationAccuracyNone;
// Determine the maximum desired accuracy for all existing location requests (does not include the new request we're currently adding)
for (INTULocationRequest *locationRequest in self.locationRequests) {
for (INTULocationRequest *locationRequest in [self activeLocationRequestsExcludingType:INTULocationRequestTypeSignificantChanges]) {
if (locationRequest.desiredAccuracy > maximumDesiredAccuracy) {
maximumDesiredAccuracy = locationRequest.desiredAccuracy;
}
Expand Down Expand Up @@ -331,7 +331,7 @@ - (void)removeLocationRequest:(INTULocationRequest *)locationRequest
{
// Determine the maximum desired accuracy for all remaining location requests
INTULocationAccuracy maximumDesiredAccuracy = INTULocationAccuracyNone;
for (INTULocationRequest *locationRequest in self.locationRequests) {
for (INTULocationRequest *locationRequest in [self activeLocationRequestsExcludingType:INTULocationRequestTypeSignificantChanges]) {
if (locationRequest.desiredAccuracy > maximumDesiredAccuracy) {
maximumDesiredAccuracy = locationRequest.desiredAccuracy;
}
Expand Down Expand Up @@ -439,7 +439,7 @@ - (void)startMonitoringSignificantLocationChangesIfNeeded
{
[self requestAuthorizationIfNeeded];

NSArray *locationRequests = [self pendingLocationRequestsWithType:INTULocationRequestTypeSignificantChanges];
NSArray *locationRequests = [self activeLocationRequestsWithType:INTULocationRequestTypeSignificantChanges];
if (locationRequests.count == 0) {
[self.locationManager startMonitoringSignificantLocationChanges];
if (self.isMonitoringSignificantLocationChanges == NO) {
Expand All @@ -459,7 +459,7 @@ - (void)startUpdatingLocationIfNeeded
// We only enable location updates while there are open location requests, so power usage isn't a concern.
// As a result, we use the Best accuracy on CLLocationManager so that we can quickly get a fix on the location,
// clear out the pending location requests, and then power down the location services.
NSArray *locationRequests = [self pendingLocationRequestsExcludingRequestsWithType:INTULocationRequestTypeSignificantChanges];
NSArray *locationRequests = [self activeLocationRequestsExcludingType:INTULocationRequestTypeSignificantChanges];
if (locationRequests.count == 0) {
[self.locationManager startUpdatingLocation];
if (self.isUpdatingLocation == NO) {
Expand All @@ -471,7 +471,7 @@ - (void)startUpdatingLocationIfNeeded

- (void)stopMonitoringSignificantLocationChangesIfPossible
{
NSArray *locationRequests = [self pendingLocationRequestsWithType:INTULocationRequestTypeSignificantChanges];
NSArray *locationRequests = [self activeLocationRequestsWithType:INTULocationRequestTypeSignificantChanges];
if (locationRequests.count == 0) {
[self.locationManager stopMonitoringSignificantLocationChanges];
if (self.isMonitoringSignificantLocationChanges) {
Expand All @@ -487,7 +487,7 @@ - (void)stopMonitoringSignificantLocationChangesIfPossible
*/
- (void)stopUpdatingLocationIfPossible
{
NSArray *locationRequests = [self pendingLocationRequestsExcludingRequestsWithType:INTULocationRequestTypeSignificantChanges];
NSArray *locationRequests = [self activeLocationRequestsExcludingType:INTULocationRequestTypeSignificantChanges];
if (locationRequests.count == 0) {
[self.locationManager stopUpdatingLocation];
if (self.isUpdatingLocation) {
Expand Down Expand Up @@ -597,7 +597,7 @@ - (void)processRecurringRequest:(INTULocationRequest *)locationRequest
/**
Returns all pending location requests with the given type.
*/
- (NSArray *)pendingLocationRequestsWithType:(INTULocationRequestType)locationRequestType
- (NSArray *)activeLocationRequestsWithType:(INTULocationRequestType)locationRequestType
{
return [self.locationRequests filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(INTULocationRequest *evaluatedObject, NSDictionary *bindings) {
return evaluatedObject.type == locationRequestType;
Expand All @@ -607,7 +607,7 @@ - (NSArray *)pendingLocationRequestsWithType:(INTULocationRequestType)locationRe
/**
Returns all pending location requests excluding requests with the given type.
*/
- (NSArray *)pendingLocationRequestsExcludingRequestsWithType:(INTULocationRequestType)locationRequestType
- (NSArray *)activeLocationRequestsExcludingType:(INTULocationRequestType)locationRequestType
{
return [self.locationRequests filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(INTULocationRequest *evaluatedObject, NSDictionary *bindings) {
return evaluatedObject.type != locationRequestType;
Expand Down

0 comments on commit 103614d

Please sign in to comment.