【发布时间】:2015-04-13 08:37:39
【问题描述】:
Core Location 使用情况最近发生了变化,但即使更新到新规范,我似乎也无法正常工作。
我尝试使用仅在 GPS 坐标查找或失败时更改其背景颜色的视图控制器开始一个新项目。
#import "ViewController.h"
@interface ViewController (){
CLLocationManager *locationManager;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (locationManager == nil)
{
locationManager = [[CLLocationManager alloc] init];
}
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if (![CLLocationManager locationServicesEnabled]) {
[self.view setBackgroundColor:[UIColor redColor]];
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark CLLocationManagerDelegate
//
//
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
{
[self.view setBackgroundColor:[UIColor greenColor]];
NSLog(@"lat:%f lon:%f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
//Debug(@"did fail with error. stop updating and return error.");
[self.view setBackgroundColor:[UIColor orangeColor]];
}
@end
我加了
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs your location to provide the best service.</string>
到 Info.plist 文件,但仍然...没有变化,位置图标出现在电池附近的状态栏上,但没有出现任何位置,无论是真实的还是模拟的。
我错过了什么吗?
【问题讨论】:
标签: ios objective-c ios8 core-location