【发布时间】:2013-02-20 15:51:50
【问题描述】:
我的应用程序中的 core location 逻辑有问题。以下代码在rootviewcontroller 中。它应该测试用户是否为应用开启或关闭了允许的 gps/定位服务,然后做出决定并转到两个view controllers 之一。
应用程序应在启动时运行此测试。此外,如果用户进入device Settings 并更改Privacy > Location Services > App Name > ON/OFF 并重新启动应用程序,那么它应该再次执行该过程。
这是我目前的代码:
#import <CoreLocation/CoreLocation.h>
-(void) viewWillAppear:(BOOL)animated {
CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];
#ifdef DEBUG
NSLog(@"RootViewController");
#endif
spinner = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = self.view.center;
spinner.hidesWhenStopped = YES;
[self.view addSubview:spinner];
[spinner startAnimating];
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusDenied) {
// denied
[self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];
[CLController.locMgr stopUpdatingLocation];
}else if (status == kCLAuthorizationStatusAuthorized) {
// allowed
[self performSegueWithIdentifier: @"SegueOffersGPS" sender: self];
[CLController.locMgr stopUpdatingLocation];
}
}
- (void)locationUpdate:(CLLocation *)location {
//locLabel.text = [location description];
#ifdef DEBUG
NSLog(@"auth status is %u", [CLLocationManager authorizationStatus]);
#endif
[self performSegueWithIdentifier: @"SegueOffersGPS" sender: self];
}
- (void)locationError:(NSError *)error {
[self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"SegueOffersNoGPS"])
{
self.navigationController.toolbarHidden=YES;
#ifdef DEBUG
NSLog(@"auth status no GPS");
#endif
}
if ([[segue identifier] isEqualToString:@"SegueOffersGPS"])
{
self.navigationController.toolbarHidden=NO;
#ifdef DEBUG
NSLog(@"auth status is GPS");
#endif
}
}
-(void)viewDidDisappear:(BOOL)animated {
[CLController.locMgr stopUpdatingLocation];
[spinner stopAnimating];
}
感谢您的帮助。
仅供参考:我之前确实问过这个问题,并认为它已经解决了。但它仍然存在,我无法弄清楚......
【问题讨论】:
-
运行这个会发生什么?
标签: iphone ios objective-c core-location cllocationmanager