【发布时间】:2017-12-10 22:13:11
【问题描述】:
Xcode 9.1 斯威夫特 4
这是我在控制台中遇到的错误: [常见]_BSMachError:端口6507; (os/kern) 无效能力 (0x14) “无法插入 COPY_SEND”
我正在尝试让我的地图在模拟器中显示用户位置(自定义位置)并居中并放大该位置。我已经实现了
隐私 - 始终定位和使用时使用说明
隐私 - 使用时的位置使用说明
隐私 - 位置始终使用说明
在 info.plist 中所有的字符串值。
这是我的 MapVC 视图控制器中的代码:
import UIKit
import MapKit
import CoreLocation
class MapVC: UIViewController {
@IBOutlet weak var mapView: MKMapView!
var locationManager = CLLocationManager()
let authorizationStatus = CLLocationManager.authorizationStatus()
let regionRadius: Double = 1000
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
locationManager.delegate = self
configureLocationServices()
mapView.showsUserLocation = true
}
}
extension MapVC: MKMapViewDelegate {
func centerMapOnUserLocation() {
guard let coordinate = locationManager.location?.coordinate else { return }
let coordinateRegion = MKCoordinateRegionMakeWithDistance(coordinate, regionRadius * 2.0, regionRadius * 2.0)
mapView.setRegion(coordinateRegion, animated: true)
}
}
extension MapVC: CLLocationManagerDelegate {
func configureLocationServices() {
if authorizationStatus == .notDetermined {
locationManager.requestAlwaysAuthorization()
} else {
return
}
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
centerMapOnUserLocation()
}
}
运行应用程序时,会出现“访问位置”弹出窗口,我选择“始终允许”或“仅在使用应用程序时”。弹出窗口消失,在检查模拟器的隐私设置时,它反映了我的选择。然而,在那之后什么也没有发生。我怀疑守卫让坐标没有返回任何坐标,所以它是“否则 {return} 正在被调用并可能停在那里?现在这是有趣的部分。如果我进入设置/隐私并选择其他可用的允许选项,当我回到应用程序,它完全按照我的意愿执行 centerMapOnUserLocation。
我已经尝试了在 SO 和其他网站上可以找到的几乎所有适用的建议。似乎没有任何效果。我已经尝试从头开始重建应用程序 3 次,结果都相同。我刚刚更新到 Xcode 9.2 时遇到了同样的问题。任何帮助将不胜感激。提前致谢!!需要任何其他信息,请告诉我,我会发布。
【问题讨论】: