Created
April 19, 2012 15:53
-
-
Save kwylez/2421928 to your computer and use it in GitHub Desktop.
Sample VC implementing shared location manager using KVO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)dealloc { | |
[super dealloc]; | |
[[CWCLocationManager sharedInstance] removeObserver:self | |
forKeyPath:@"currentLocation"]; | |
} | |
- (id)init { | |
self = [super init]; | |
if (self) { | |
} | |
return self; | |
} | |
- (void)viewDidUnload { | |
[super viewDidUnload]; | |
[[CWCLocationManager shareInstance] removeObserver:self forKeyPath:@"currentLocation"]; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
CWCLocationManager *manager = [CWCLocationManager sharedInstance]; | |
[manager addObserver:self | |
forKeyPath:@"currentLocation" | |
options:NSKeyValueObservingOptionNew | |
context:NULL]; | |
} | |
#pragma mark - Public Methods | |
- (void)callSuperCoolMethodThatNeedsCoordinate:(CLLocationCoordinate2D)coord { | |
// post something cool from location | |
} | |
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
if ([keyPath isEqual:@"currentLocation"]) { | |
if ([CWCLocationManager sharedInstance].currentLocation) { | |
[[CWCLocationManager sharedInstance] stop]; | |
CLLocationCoordinate2D currentLoc = [CWCLocationManager sharedInstance].currentLocation.coordinate; | |
[self callSuperCoolMethodThatNeedsCoordinate:currentLoc]; | |
} | |
} else { | |
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment