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

这是我的代码:

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

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

【问题讨论】:

标签: objective-c iphone location ios8 cllocationmanager


【解决方案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 条目 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 2023-03-07
    • 2014-08-21
    相关资源
    最近更新 更多