ios11 didUpdateLocations不叫

问题描述:

我正在使用CLLocationManager开发iOS应用程序。ios11 didUpdateLocations不叫

直到ios10,我调用了startUpdatingLocation,然后didUpdateLocations被调用,并且我得到了位置信息。

现在,我更新了iOS11 beta9和Xcode beta6。 我称为startUpdatingLocation,但didUpdateLocations未被调用。 所以我不能得到任何位置。

位置是我的应用程序的核心信息。 有没有人遇到同样的问题?或者可以解决这个问题? 对不起我的英文不好。谢谢。

+1

你可以添加你的代码吗? –

+0

谢谢你的提问。但我解决了这个问题。答案在问题 –

+0

的评论下方,如果您认为这有助于他人或删除您的问题,请将实际答案与解决方案一起发布。 – rmaddy

在iOS 11中,在info.plist中添加了新的隐私密钥,您应该添加其中的任何一个,希望info.plist中的添加为您工作。

/* 
*  Either the NSLocationAlwaysAndWhenInUseUsageDescription key or both the 
*  NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription 
*  keys must be specified in your Info.plist; otherwise, this method will do 
*  nothing, as your app will be assumed not to support Always authorization. 
*/ 
+0

谢谢!我解决了这个问题。我使用“requestAlwaysAuthorization”获取权限,但问题出在这里。我必须使用iOS11的“requestWhenInUseAuthorization”。我修复后,didUpdateLocations被调用。 –

添加在Info.plsit

privacy - location usage description 
Privacy - Location When In Use Usage Description 
Application NSLocationAlwaysUsageDescription 

enter image description here

+0

感谢您的回答,但我需要更改如何获得用户权限。 –

+0

这三个字符串将显示弹出窗口以获取权限。 –

我有一个不同的问题。我不小心将该方法声明为类方法而不是实例方法。

+ (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations 

而不是

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations 

一旦我改变 “+” 到 “ - ”,一切运行良好。