首先在info.plist中的key下写入NSLocationWhenInUsageDescription,输入你想提醒用户的内容,之后在.m文件中实现如下代码:
//判断定位服务是否打开
if (![CLLocationManager locationServicesEnabled]) {
NSLog(@"尚未打开");
}else {
NSLog(@"打开了");
}
//如果没有授权则请求授权
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
[self.locationManager requestWhenInUseAuthorization];
}
这样就能请求定位服务了。