【发布时间】:2014-10-26 20:35:39
【问题描述】:
我什至无法让最简单的位置更新代码工作。我有一个位置应用程序可以正常运行一年多,现在当我尝试编译和运行它(升级到 xcode 6.1 并且没有更改代码之后),在调用 startUpdatingLocation 之后,didUpdateLocations 回调永远不会触发,我可以看到 gps 指示器从未出现在电池指示器旁边。 我已经开始了一个新的测试项目,除了尝试注册位置更新之外什么都不做,但结果仍然相同:设备或模拟器上没有位置更新。 下面是测试项目的单视图控制器的代码:
//ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
}
@property (strong, nonatomic) CLLocationManager* locationManager;
@end
//ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"got a location");
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Error: %@",error.description);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"got a location");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
如果使用最新版本的 xcode 的人可以创建一个这样的项目,该项目除了接收位置更新、验证它是否有效并完整发布代码之外什么都不做,那就太棒了。我已尝试将内容添加到 plist 文件以及类似问题的所有其他补救措施均无济于事。
【问题讨论】:
-
当我将 NSLocationWhenInUseUsageDescription 添加到 info.plist 时,对我来说效果很好。您的代码已复制并粘贴到新的单一视图应用程序中。
标签: ios cllocationmanager