didUpdateToLocation未被调用 [英] didUpdateToLocation is not called
问题描述
我想接收位置更新。
我添加了一个位置委托给头:
@interface AppDelegate:UIResponder< UIApplicationDelegate,CLLocationManagerDelegate>
和以下函数:
- )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//初始化位置管理器
CLLocationManager * locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
// [locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@SomeViewControllerbundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
//一些问题
}
- :(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//一些动作
}
但是不会调用 didUpdateToLocation
或 didFailWithError
模拟器和设备上)。
提前感谢,
Luda
PS:这将有助于使您的位置管理器成为一个实例变量,所以它将由方法 - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
完成后保留。
I want to receive location updates. I have added a location delegate to the header:
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
and the following functions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//initialize location manager
CLLocationManager* locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
// [locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
//Some problem
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
//Some action
}
But neither didUpdateToLocation
nor didFailWithError
are called (same problem on the simulator and on the device). What am I missing?
Thanks in advance,
Luda
Are location services for your application enabled?
P.S: it would help to make your location manager an instance variable so it will be retained by ARC after the method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
is completed.
这篇关于didUpdateToLocation未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!