gpt4 book ai didi

iphone - didUpdateToLocation 未调用

转载 作者:行者123 更新时间:2023-12-03 20:42:47 24 4
gpt4 key购买 nike

我想接收位置更新。我已将位置委托(delegate)添加到 header :

@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>

以及以下功能:

- (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
}

但两者都不是didUpdateToLocation也不didFailWithError被调用(模拟器和设备上的问题相同)。我错过了什么?

提前致谢,

路达

最佳答案

您的应用程序是否启用了位置服务?

P.S:这将有助于使您的位置管理器成为一个实例变量,以便在方法- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions之后由ARC保留它 已完成。

关于iphone - didUpdateToLocation 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10893884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com