即使最简单的位置更新代码工作也无法实现。我有一个位置应用,运行良好一年多了,现在当我尝试编译并运行它(在升级到xcode 6.1并且没有更改代码之后),在调用startUpdatingLocation之后,didUpdateLocations回调从不会触发,而我可以看到gps指示符不会出现在电池指示符旁边。 我已经开始了一个新的测试项目,它除了尝试注册位置更新,并且仍然是相同的结果:在设备或模拟器上没有位置更新。 下面是测试项目的单一视图控制器代码:startUpdatingLocation不再在XCode 6.1中工作
//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时,对我来说工作得很好。您的代码被复制并粘贴到一个新的单一视图应用程序中。 – InsertWittyName 2014-10-26 20:44:26