MKMapview
当前用户位置未触发iOS-8
,以前的iOS-7
& iOS-6
工作正常。
self.mapView.delegate = self;
self.mapView.showsUserLocation =YES;
在这一行中自动调用用户当前位置的委托方法
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
}
但它没有火iOS-8
.
在iOS8中,您需要在获取用户的位置之前请求用户的授权。
请求有两种:
-[CLLocationManager requestWhenInUseAuthorization]
仅当应用程序被唤醒时,您才可以获取用户的位置。
-[CLLocationManager requestAlwaysAuthorization]
让您即使在后台也能获取用户的位置。
您可以相应地在它们之间进行选择。
例如,在开始更新位置之前放置此内容:
// ask for authorization
CLLocationManager * locationManager = [[CLLocationManager alloc] init];
// check before requesting, otherwise it might crash in older version
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
此外,不要忘记添加两个键
NSLocationWhenInUseUsageDescription
and
NSLocationAlwaysUsageDescription
进入你的info.plist。
将值留空以使用默认消息,或者您可以通过输入值自定义自己的消息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)