MKMapview
当前用户位置在iOS-8
中未触发,以前的iOS-7
和iOS-6
工作正常。
self.mapView.delegate = self;
self.mapView.showsUserLocation =YES;
在这一行中自动调用用户当前的位置委托方法
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
}
但它不会在iOS-8
中触发。
发布于 2014-09-20 06:40:42
在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
和
NSLocationAlwaysUsageDescription
添加到你的info.plist中。
将值保留为空以使用默认消息,或者您可以通过输入值来自定义您自己的消息。
发布于 2014-10-16 18:33:28
在ios 8中,需要进行如下授权
NSString * osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue]>= 8.0 ) {
[_CLLocationManager requestAlwaysAuthorization]; //Requests permission to use location services whenever the app is running.
// [_CLLocationManager requestWhenInUseAuthorization]; //Requests permission to use location services while the app is in the foreground.
}
[_CLLocationManager startUpdatingLocation];
并且您需要在plist中添加两个键
1.NSLocationAlwaysUsageDescription
2.NSLocationWhenInUseUsageDescription
发布于 2014-10-08 13:48:33
在iOS 8 Mapview中,当前位置使用
您可以在.plist文件中设置
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your app name Or Other string</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your app name Or Other string</string>
在你的代码端,你只需要实现这个
CLLocationManager * locationmanager = CLLocationManager新;
locationmanager.delegate = self;
locationmanager.distanceFilter = kCLDistanceFilterNone;
locationmanager.desiredAccuracy = kCLLocationAccuracyBest;
[locationmanager startUpdatingLocation];
[locationmanager requestAlwaysAuthorization];
-(空)locationManager:(CLLocationManager*)管理器didUpdateLocations:(NSArray *)位置{
location = [locations objectAtIndex:0];
[locationmanager stopUpdatingLocation];
}
我正在使用我的应用程序获得完美的当前位置。
https://stackoverflow.com/questions/25911330
复制相似问题