简体   繁体   English

iOS 8中的定位服务损坏

[英]Location services broken in iOS 8

I have an app that want to get user location. 我有一个想要获取用户位置的应用程序。 As you may know, Apple change user private policy (as i suggest) and, now i can't get user location. 如您所知,Apple更改了用户私有策略(如我所建议),现在我无法获得用户位置。 It show no error, no warning, nothing. 它显示没有错误,没有警告,什么都没有。 In attempt to fix this i add following code before calling [_locationManager startUpdatingLocation]; 为了解决这个问题,我在调用[_locationManager startUpdatingLocation];之前添加了以下代码[_locationManager startUpdatingLocation]; There it is: 那里是:

CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus];

    if (authStatus == kCLAuthorizationStatusNotDetermined) {
        [_locationManager requestWhenInUseAuthorization];
        NSLog(@"Case 1");
        return;
    };

    if (authStatus == kCLAuthorizationStatusDenied || authStatus == kCLAuthorizationStatusRestricted) {
        // show an alert
        NSLog(@"Case 2");
        return;
    };

And output is Case 1, which mean - authStatus == kCLAuthorizationStatusNotDetermined . 输出为案例1,表示authStatus == kCLAuthorizationStatusNotDetermined But there is no alert, no prompt, no suggestion to user to enable location services for my app. 但是没有警报,提示,也没有建议用户为我的应用启用位置服务。 Actually, i even turn it on manually in settings of my iPhone. 实际上,我什至在iPhone的设置中手动将其打开。 Still, not working (it work perfectly before Xcode update). 仍然不能正常工作(在Xcode更新之前可以正常工作)。

How to fix that? 如何解决? Any advices would be appreciated, thanks! 任何建议,将不胜感激,谢谢!

You need to add a reasoning in your info.plist as to why you are going to request a users location. 您需要在info.plist中添加有关为什么要请求用户位置的理由。

Open info.plist add a row with a key of NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription , a type of String, and for the value type in why you want to request the users location. 打开info.plist,添加一个带有NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription键(字符串类型)的键的行,并为值类型指定为什么要请求用户位置。 For example, "Uses location to calculate the sunrise and sunset". 例如,“使用位置来计算日出和日落”。 iOS will not ask a user for permission to use their location unless you have given a reason as to why you are requesting it. 除非您给出要求的理由,否则iOS不会询问用户使用其位置的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM