I’m a newbie to programming for iPhone, I’m following along this book.
I’m stuck at the example in Chapter 4, Delegation and Core Location.
Here’s the code I’ve written so far:
WhereamiAppdelegate.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WhereamiAppDelegate : NSObject <UIApplicationDelegate, CLLocationManagerDelegate> {
UIWindow *window;
CLLocation *locationManager;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
And here is the implementation file:
I have only included the changes that I’ve made.
The entire file is here.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create location manager.
locationManager = [[CLLocation alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[locationManager setDelegate:nil];
[_window release];
[super dealloc];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@",newLocation);
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Couldn't find loaction %@",error);
}
XCode gives me a warning that says CLLocation may not respond to setDistanceFilter and other similar warnings.
I am clueless here, I have followed the book line to line.
I think that I haven’t implemented a necessary protocol or something.
Can someone please tell me what I’m doing wrong and how I should proceed further.
The class
CLLocationis not the same asCLLocationManager. The former represents one location, while the latter is the manager class that handles configuring location updates for your application.