Ios 未使用MapView工具包定位用户位置
当应用程序运行时,它给了我以下信息: 尝试在不提示位置授权的情况下启动MapKit位置更新。必须首先调用-[CLLocationManager RequestWhenUseAuthorization]或-[CLLocationManager requestAlwaysAuthorization] 我知道这是因为我们必须首先要求用户使用他的位置,我按照他们的建议做了:Ios 未使用MapView工具包定位用户位置,ios,objective-c,mapkit,core-location,Ios,Objective C,Mapkit,Core Location,当应用程序运行时,它给了我以下信息: 尝试在不提示位置授权的情况下启动MapKit位置更新。必须首先调用-[CLLocationManager RequestWhenUseAuthorization]或-[CLLocationManager requestAlwaysAuthorization] 我知道这是因为我们必须首先要求用户使用他的位置,我按照他们的建议做了: <key>NSLocationAlwaysUsageDescription</key> <strin
<key>NSLocationAlwaysUsageDescription</key>
<string>Message</string>
or/and
<key>NSLocationWhenInUseUsageDescription</key>
<string>Message</string>
NSLocationAlwaysUsageDescription
消息
或/及
NSLocationWhenUse用途说明
消息
int Info.plist文件
下面是它的外观:
但是它给了我这个信息,并且没有在iOS模拟器或设备(iPad)中找到设备。在iOS 8上进行此授权
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 &&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedWhenInUse
//[CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways
) {
// Will open an confirm dialog to get user's approval
[locationManager requestWhenInUseAuthorization];
[locationManager requestAlwaysAuthorization];
//[_locationManager requestAlwaysAuthorization];
} else {
[locationManager startUpdatingLocation]; //Will update location immediately
}
试试这个:
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
在实现你的类之前
这是:
#ifdef __IPHONE_8_0
if(IS_OS_8_OR_LATER) {
[self.locationManager requestWhenInUseAuthorization];
}
#endif
[self.locationManager startUpdatingLocation];
或:
不是两者都有。
对我来说,我是在viewDidLoad
方法中这样做的
一切都会好起来的;p仍会给我该消息转到项目设置-功能-后台模式-选择位置更新。然后重试。不要检查
系统版本
。有正确的方法检查API是否存在。您是否激活了映射功能?()是的,我找到了,但我很生气地找到了解决办法。我会发布我自己的答案,这样这个问题就可以解决了,非常感谢。不要使用IS_OS_8_或_稍后。有适当的方法检查API是否存在。
#ifdef __IPHONE_8_0
if(IS_OS_8_OR_LATER) {
[self.locationManager requestAlwaysAuthorization];
}
#endif
[self.locationManager startUpdatingLocation];