An Example Of Implementing The Location Services Framework Callbacks
Include File
You probably need to include the file for the class that will call you back via the delegate in your .h file:
#import <CoreLocation/CoreLocation.h>
Add The Delegate Definition To Your Class Declaration
@interface WhereamiAppDelegate : NSObject
<UIApplicationDelegate, CLLocationManagerDelegate> //A delegate is an input to the class so it goes here, after the default UIApplicationDelegate
Declare the Object In Your .h File
CLLocationManager *locationManager;
Setup The Object And Callbacks
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
//Carry out other init tasks on the object...
Clear The Delegate In dealloc
If we could be deallocated then we need to ensure that the delegate pointer gets set to nil:
- (void)dealloc {
[locationManager setDelegate:nil]; //- Added this
[managedObjectContext_ release];
[managedObjectModel_ release];
[persistentStoreCoordinator_ release];
[window release];
[super dealloc];
}
Create The Callbacks
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@", newLocation);
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Could not find location: %@", error);
}