不使用MapView Kit定位用户位置

时间:2015-02-12 16:08:21

标签: ios objective-c mapkit core-location

当应用程序运行时,它给了我这个:

尝试在不提示位置授权的情况下启动MapKit位置更新。必须首先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]。

我知道这是因为我们必须首先要求用户使用他的位置,我按照他们的建议做了:

<key>NSLocationAlwaysUsageDescription</key>
<string>Message</string>

  or/and

<key>NSLocationWhenInUseUsageDescription</key>
<string>Message</string>

在Info.plist文件中

它的外观如下:

MapKit View

Info.plist 但它钢铁给我这个消息,并没有在iOS模拟器或设备(iPad)中找到该设备。

2 个答案:

答案 0 :(得分:0)

试试这个:

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

或:

#ifdef __IPHONE_8_0
    if(IS_OS_8_OR_LATER) {
        [self.locationManager requestAlwaysAuthorization];
    }
#endif
    [self.locationManager startUpdatingLocation];
不是两者兼而有之。 对我来说,我在viewDidLoad方法

中这样做

没关系; p

答案 1 :(得分:-1)

在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
    }