cllocationmanager不要求用户权限ios8

Posted

技术标签:

【中文标题】cllocationmanager不要求用户权限ios8【英文标题】:cllocationmanager not asking for user permission ios8 【发布时间】:2014-11-14 18:13:29 【问题描述】:

这是我的代码:

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

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

【问题讨论】:

通过这个...***.com/questions/24062509/… 【参考方案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。

希望这会有所帮助。

【讨论】:

【参考方案2】:

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

【讨论】:

我错过了 .plist 条目 :)

以上是关于cllocationmanager不要求用户权限ios8的主要内容,如果未能解决你的问题,请参考以下文章