对于以下代码行:
let currentLocationCoordinates = locationManager.requestLocation()
我收到这个警告:
常量'currentLocationCoordinates'推断为类型为'Void',这可能是意外的
在Info.plist中,我添加了以下密钥:
'locationManager'在类属性中定义:
let locationManager = CLLocationManager()
我搜索了很多,没有找到任何解决方案。你有什么建议吗?谢谢!
你需要
let locationManager = CLLocationManager()
locationManager.delegate = self
class MYVC:UIViewController,CLLocationManagerDelegate { --- }
func locationManager(_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation]) { --- }
这个locationManager.requestLocation()
返回void而不是当前位置,它开始查询当前位置然后调用didUpdateLocations
获取它所以你可能print(locations.last)
,你也可能只需要
隐私 - 位置始终和何时使用用法说明
因为它包含其他2个权限