iOS 8 Mapview当前位置不会激发 [英] iOS 8 Mapview Current Location not fire

查看:77
本文介绍了iOS 8 Mapview当前位置不会激发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MKMapview 当前用户位置未在 iOS-8 中触发,之前的 iOS-7 & iOS-6 工作正常。

MKMapview current user location not fire in iOS-8,previous iOS-7 & iOS-6 are working fine.

     self.mapView.delegate = self;
     self.mapView.showsUserLocation =YES; 

在此行中自动调用用户当前位置委托方法

In this line to call automatically the user current location delegate methods

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
}

但不会在 iOS-8 中触发。

推荐答案

在iOS8中,您需要在获取用户位置之前请求用户授权。

In iOS8, you need to request user's authorization before getting their location.

有两种请求:

- [CLLocationManager requestWhenInUseAuthorization] 只有在应用程序被唤醒时才能获取用户的位置。

-[CLLocationManager requestWhenInUseAuthorization] lets you get users' location only when the app is awaken.

- [CLLocationManager requestAlwaysAuthorization] 可让您获取用户的位置,即使它位于后台。

-[CLLocationManager requestAlwaysAuthorization] lets you get users' location even when it's in the background.

您可以相应地选择它们。

You can choose between them accordingly.

例如,在开始更新位置之前将其放入:

For example, put this before you start updating location:

// 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];

}

此外,不要忘记添加两个键

Furthermore, don't forget to add two keys

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

进入你的info.plist。

into your info.plist.

将值保留为空以使用默认消息,或者您可以通过输入值来自定义自己的值。

Leave the values empty to use the default messages or you can customize your own by inputting the values.

这篇关于iOS 8 Mapview当前位置不会激发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆