我无法添加locationManager.requestWhenInUseAuthorization()
我期望的是:弹出窗口询问用户的位置权限 什么东西:什么都没显示
设置:iphone中的位置设置:从不
Plist:
LocationAlwaysAndWhenInuseUsageDescription
LocationAlwaysUsageDescription
LocationWhenInUseUsageDescription
import Foundation
import UIKit
import CoreLocation
class NoobNoobVC: BaseVC, CLLocationManagerDelegate {
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.distanceFilter = 5
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
//locationManager.startUpdatingHeading()
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
locationManager.requestWhenInUseAuthorization()
}
}
答案 0 :(得分:0)
每当未确定当前授权状态(
requestWhenInUseAuthorization()
)时,您都可以致电CLAuthorizationStatus.notDetermined
。
&
如果初始授权状态不是
CLAuthorizationStatus.notDetermined
,则此方法不执行任何操作,也不会调用locationManager(_:didChangeAuthorization:)
方法。
您必须使用authorizationStatus()
来检查授权状态,然后采取适当的措施,例如-通知用户出了什么问题,...以及可以采取哪些措施。只有requestWhenInUseAuthorization()
,您才能呼叫.notDetermined
。此类函数被标记为已弃用,如果您的目标iOS> = 14.0,则应使用instance variant。