I’m writing a notification center widget, and it had to use location information. In normal apps I use CoreLocation and it works fine. But in my widget, I tried to locationServicesEnabled but it didn’t go to the callback functions, and the authorizationStatus is always kCLAuthorizationStatusNotDetermined, and the authorize setting didn’t show up in Setting -> location service. I already set the delegate to the class.
The system’s Yahoo weather widget can auto locating and it uses CoreLocation too, so the widget do have ability to use location service.
Why CoreLocation doesn’t work on my widget?
Update: 2012.10.24 15:52
I use private API
[CLLocationManager setAuthorizationStatus:YES
forBundle:[NSBundle bundleForClass:self.class]]
Now, the authorize setting shows in the Setting->location service. And every time I pull down the notification center, it turns on. But the authorizationStatusis still kCLAuthorizationStatusNotDetermined and won’t go to the callback functions.
Update: 2012.10.25 10:38
I change my locating code to:
[CLLocationManager setDefaultEffectiveBundle:[NSBundle bundleForClass:self.class]];
[_locationManager startUpdatingLocation];
If I turn off location service, it will jump to
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
If I turn the service on, no matter I authorize it or not, there’s no calling back (both
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
and
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
won’t be invoked).
By the way, when I turn on/off the service,
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
will be invoked, but not when I change the authorizationStatus.
Maybe it’s because a WeeAppPlugin bundle is not a effective bundle that cause the widget cant’s use location service. After I user
[[CLLocationManager alloc] initWithEffectiveBundle:[NSBundle bundleForClass:self.class]]in private API of CoreLocation, the widget can get location info normally.