【发布时间】:2011-11-02 02:42:01
【问题描述】:
我是 iPhone 编程的新手,我正在关注this 的书。 我停留在第 4 章中的示例,委派和核心位置。
这是我目前编写的代码: 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
这里是实现文件: 我只包括了我所做的更改。 整个文件是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 给我一个警告说 CLLocation 可能不会响应 setDistanceFilter 和其他类似的警告。 我在这里一无所知,我已经按照书本一行行。 我认为我还没有实现必要的协议或其他东西。 有人可以告诉我我做错了什么以及我应该如何继续。
【问题讨论】:
标签: iphone ios core-location