2014-09-27 85 views
-1

我有一个应用程序想获取用户位置。正如你可能知道,苹果改变用户的私人政策(如我建议),现在我无法获得用户的位置。它显示没有错误,没有警告,什么都没有。在尝试调用[_locationManager startUpdatingLocation]; 之前解决这个我添加以下代码在那里,它是:iOS 8中破解的位置服务

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

和输出是情况1,这意味着 - authStatus == kCLAuthorizationStatusNotDetermined。 但没有提醒,没有提示,没有建议用户启用我的应用程序的位置服务。实际上,我甚至在我的iPhone设置中手动打开它。仍然不工作(它在Xcode更新之前完美工作)。

如何解决这个问题? 任何意见,将不胜感激,谢谢!

+0

您应该始终调用'requestWhenInUseAuthorization'来移除if语句。另外,您是否已将所需的密钥添加到您的info.plist中? – Paulw11 2014-09-27 21:32:05

+0

[Xcode 6 GM - CLLocationManager]可能的重复(http://stackoverflow.com/questions/25844430/xcode-6-gm-cllocationmanager) – 2014-09-27 21:52:29

+0

在http://datacalculation.blogspot.in/2014/11找到描述性解决方案/how-to-fix-cllocationmanager-location.html – 2014-11-02 17:19:27

回答

3

您需要在您的info.plist中添加推理,以了解您为什么要请求用户位置。

打开info.plist添加一行的密钥NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription,一种字符串,以及为什么要请求用户位置的值类型。例如,“使用位置来计算日出和日落”。除非你给出了你为什么要求它的理由,否则iOS不会要求用户使用他们的位置。

+0

感谢TyloBedo的帮助! – 2014-09-28 07:17:10

+0

欲了解更多描述,你可以访问http://datacalculation.blogspot.in/2014/11/how-to-fix-cllocationmanager-location.html – 2014-11-02 17:20:27