【发布时间】:2012-10-14 03:23:03
【问题描述】:
我正在编写一个通知中心小部件,它必须使用位置信息。在普通应用程序中,我使用 CoreLocation 并且效果很好。但是在我的小部件中,我尝试了locationServicesEnabled,但它没有转到回调函数,authorizationStatus 始终是kCLAuthorizationStatusNotDetermined,并且授权设置没有出现在 Setting -> 位置服务。我已经将代表设置为班级。
系统的Yahoo天气小部件可以自动定位,它也使用CoreLocation,所以小部件确实有使用定位服务的能力。
为什么 CoreLocation 在我的小部件上不起作用?
更新:2012.10.24 15:52
我使用私有 API
[CLLocationManager setAuthorizationStatus:YES
forBundle:[NSBundle bundleForClass:self.class]]
现在,授权设置显示在设置->位置服务中。每次我拉下通知中心,它都会打开。但是authorizationStatus仍然是kCLAuthorizationStatusNotDetermined,不会去回调函数。
更新:2012.10.25 10:38
我将定位码更改为:
[CLLocationManager setDefaultEffectiveBundle:[NSBundle bundleForClass:self.class]];
[_locationManager startUpdatingLocation];
如果我关闭定位服务,它会跳转到
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
如果我开启了服务,无论我授权与否,都没有回调(无论是
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
和
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
不会被调用)。
顺便说一下,当我打开/关闭服务时,
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
将被调用,但不会在我更改授权状态时调用。
【问题讨论】:
标签: ios widget core-location jailbreak