永远不会调用iOS 8 CLLocationManagerDelegate方法 [英] iOS 8 CLLocationManagerDelegate methods are never called
本文介绍了永远不会调用iOS 8 CLLocationManagerDelegate方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//查看是否加载了方法-分配了LocationManager并将CLLocationManagerDelegate包含在.h文件中
//View did Load Method- LocationManager is allocated and have included the CLLocationManagerDelegate in .h File
-ViewDidLoad{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
self.locationManager.distanceFilter=kCLDistanceFilterNone;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager startMonitoringSignificantLocationChanges];
[self.locationManager startUpdatingLocation];
}
// Location Manager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"%@", [locations lastObject]);
}
推荐答案
在plist中,您必须添加2个条目
In plist you have to add 2 entries
- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysUsageDescription
将两者都设为需要位置才能找到您所在的位置或任何东西
Make the string of both as "Location is required to find out where you are" or anything
self.locationManager = [[CLLocationManager alloc]init];
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if (authorizationStatus == kCLAuthorizationStatusAuthorized ||
authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"You are authorized");
}
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
希望这会有所帮助
这篇关于永远不会调用iOS 8 CLLocationManagerDelegate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文