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

Fix CLLocationManager management #106

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions MapView/Map/RMMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ - (void)dealloc
{
LogMethod();

[[NSNotificationCenter defaultCenter] removeObserver:self];

[self setDelegate:nil];
[self setBackgroundView:nil];
[self setQuadTree:nil];
Expand Down Expand Up @@ -2455,6 +2457,9 @@ - (void)setShowsUserLocation:(BOOL)newShowsUserLocation
_locationManager.headingFilter = 5;
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
else
{
Expand All @@ -2464,6 +2469,9 @@ - (void)setShowsUserLocation:(BOOL)newShowsUserLocation
[_locationManager release];
_locationManager = nil;

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];

if (_delegateHasDidStopLocatingUser)
[_delegate mapViewDidStopLocatingUser:self];

Expand Down Expand Up @@ -2823,4 +2831,24 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
}
}

#pragma mark -
#pragma mark system events

- (void)applicationDidEnterBackground:(UIApplication *)application {
if (_locationManager != nil) {
[_locationManager stopUpdatingLocation];
[_locationManager stopUpdatingHeading];
}
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
if (_locationManager != nil) {
if (_showsUserLocation == YES)
[_locationManager startUpdatingLocation];

if (_userTrackingMode == RMUserTrackingModeFollowWithHeading)
[_locationManager startUpdatingHeading];
}
}

@end