As advised by Apple(如果我正确理解了这一点),那么我最初是在寻求WhenInUse
授权以启用我的应用程序的基本位置支持(我在AppDelegate
中这样做)并逐步升级权限只能在实际使用此功能的Always
中设置为ViewController
。
// AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var m_location_manager = CLLocationManager()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
m_location_manager.delegate = self
if CLLocationManager.authorizationStatus() != .authorizedWhenInUse {
m_location_manager.requestWhenInUseAuthorization()
}
}
// MyViewController
class MyViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {
var m_location_manager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
m_location_manager.delegate = self
if CLLocationManager.authorizationStatus() != .authorizedAlways {
m_location_manager.requestAlwaysAuthorization()
}
m_location_manager.desiredAccuracy = kCLLocationAccuracyBest
m_location_manager.startUpdatingLocation()
}
启动该应用程序时,确实的确询问我是否要授权WhenInUse
位置服务,一切正常。但是,在MyView
中运行时,尽管一切似乎都正常(没有崩溃,但一切似乎都正常),但在控制台中却出现了两个这样的错误:
2018-10-11 15:17:26.174617+0300 MyApp[1174:245307] [Common] _BSMachError: port cd03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
请注意,提到的端口并不总是相同的(我见过d303、163603等)。