有一个2年前的项目,我刚刚从3迅速更新为4。除了plist获得新权限外,没有任何实质性的重大变化。在真实设备上运行该应用程序,但找不到信标。 UUID,主要和次要都多次验证有效和正确。 BKON信标坐在电话旁边。
位置管理器的设置类似于在viewDidLoad
中 var locationManager:CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print("locationManager setup")
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.delegate = self
}
区域/信标设置
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedAlways {
if CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
if CLLocationManager.isRangingAvailable() {
setupBeacons()
}
}
}
}
func setupBeacons(){
print("setupBeacons")
if let beaconUUID = UUID.init(uuidString: "58de905b-3b54-bf9d-2d01-4dc018eaf6cc") {
let region1 = CLBeaconRegion(
proximityUUID: beaconUUID,
major: 998,
minor: 1330, //2121
identifier: "Crossing1")
region1.notifyOnEntry = true
region1.notifyOnExit = true
region1.notifyEntryStateOnDisplay = true
startMonitoringBeacon(region: region1)
}
}
func startMonitoringBeacon(region: CLBeaconRegion){
locationManager.startMonitoring(for: region)
locationManager.startRangingBeacons(in: region)
}
然后我像这样设置委托回叫
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
print("didRangeBeacons: found \(beacons.count)")
}
但是找不到信标。其他委托方法(rangingBeaconsDidFailFor,monitoringDidFailFor和didFailWithError)中没有错误或任何错误。我已经尝试过从locationmanager中删除所有信标,进行多次卸载,重新安装应用程序并从头开始重建应用程序。
有什么我想念的吗?