cllocationmanager没有要求用户权限ios8

时间:2014-09-20 06:29:15

标签: objective-c iphone location ios8 cllocationmanager

这是我的代码:

    if (!_locationManager)
    {
        _locationManager = [[CLLocationManager alloc] init];
        [_locationManager setDelegate:self];
    }
    [_locationManager startUpdatingLocation];

如果有人知道请帮助..谢谢

2 个答案:

答案 0 :(得分:2)

[locationManager requestAlwaysAuthorization];添加到您的代码中,并将条目NSLocationAlwaysUsageDescription添加到您的.plist中,其中的值是您要求用户许可的某种消息。

答案 1 :(得分:1)

在使用 iOS-8.0 及更高版本的位置服务时,您需要为requestWhenInUseAuthorization添加电话。找到下面的示例代码。

locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;

// this check is required for iOS 8+
// selector 'requestWhenInUseAuthorization' is first introduced in iOS 8
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [locationManager requestWhenInUseAuthorization];
}

[locationManager startUpdatingLocation];

有关详细信息,请参阅此blog

希望这有帮助。