2014-09-23 101 views
0

我正在使用CLLocationManager来获取当前位置。特别是在iOS 8中,委托方法不会被解雇。CLLocationmanager updateLocations委托方法没有在iOS 8中调用

我已经设置允许在位置服务,请参阅下列屏幕撷取画面 enter image description here

请在下面找到我的代码:

self.myLocationManager = [[CLLocationManager alloc]init]; [self.myLocationManager setDelegate:self]; self.myLocationManager.distanceFilter = kCLDistanceFilterNone; self.myLocationManager.desiredAccuracy = kCLLocationAccuracyBest; [self.myLocationManager startUpdatingLocation];

我试图使用的是iOS 8的方法。并设置的plist属性NSLocationAlwaysUsageDescription但仍然是无法得到的位置

self.myLocationManager requestAlwaysAuthorization];

+0

您必须添加以下行:[self.myLocationManager requestAlwaysAuthorization];之前[self.myLocationManager startUpdatingLocation]; – TonyMkenu 2014-10-05 22:26:44

+0

myLocationManager必须是一个强大的财产,也... – TonyMkenu 2014-10-05 22:28:09

回答

1

第1步:

添加下面的代码:

SEL requestSelector = NSSelectorFromString(@"requestAlwaysAuthorization"); 
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined && 
    [locationManager respondsToSelector:requestSelector]) { 
    [locationManager performSelector:requestSelector withObject:NULL]; 
} else { 
    [locationManager startUpdatingLocation]; 
} 

第2步:

NSLocationAlwaysUsageDescription加入info.plist

enter image description here

+0

不适合我 – Vinodh 2014-09-23 13:29:50

0

看起来您并没有为NSLocationAlwaysUsageDescription设置一个值。

+0

我增加了价值。它仍然没有开火 – Vinodh 2014-09-25 05:13:56

相关问题