我们正处于开发Swift2.2应用程序的高级阶段,因此决定在此期间迁移到2.3,并在以后进行完整的Swift 3迁移。然而,我们无法获得信标检测工作后转换为Swift 2.3。方法"didRangeBeacons“一直返回一个空数组。同样的代码在SWIFT2.2中运行,所以我们知道我们有所有的权限等等。
另外,如果我们在同一台ipad上打开"Locate“应用程序,那么我们的应用程序也会开始返回"didRangeBeacons”中的数据。已经尝试过不同版本的应用程序,而且所有的Swift2.3应用程序的行为都是一样的。不知道定位程序在做什么.有谁在同一条船上吗?
这是我们正在使用的代码。我不确定这是否应该写在这里或注释中,但无法将代码放入注释中.
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "9735BF2A-0BD1-4877-9A4E-103127349E1D")!, identifier: "testing")
// Note: make sure you replace the keys here with your own beacons' Minor Values
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.locationManager.delegate = self
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startMonitoringForRegion(self.region)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didStartMonitoringForRegion region: CLRegion) {
print("didStartMonitoringForRegion")
self.locationManager.requestStateForRegion(region)
}
func locationManager(manager: CLLocationManager, monitoringDidFailForRegion region: CLRegion?, withError error: NSError) {
print("monitoringDidFailForRegion")
}
func locationManager(manager: CLLocationManager, didDetermineState state: CLRegionState, forRegion region: CLRegion) {
print("didDetermineState")
if state == .Inside {
//Start Ranging
self.locationManager.startRangingBeaconsInRegion(self.region)
self.locationManager.startUpdatingLocation()
}
else {
//Stop Ranging here
self.locationManager.stopUpdatingLocation()
self.locationManager.stopRangingBeaconsInRegion(self.region)
}
}
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
print(beacons.count)
}}
如果我们删除self.locationManager.startMonitoringForRegion(self.region)并在self.locationManager.requestAlwaysAuthorization()之后直接调用self.locationManager.startRangingBeaconsInRegion(self.region),那么更新发布了更多的尝试,以使这个工作的应用程序在前台模式下工作
这是次优,因为我们没有进入和退出事件或状态,但至少我们得到了信标计数。
发布于 2016-09-22 13:57:46
有许多关于iOS 10信标检测问题的传闻报道。症状包括:
这可能是一个在iOS更新中修复的错误。在此之前,一些用户报告说,将XCode中的应用程序部署目标设置为9.x将解决此问题。
发布于 2016-09-23 12:59:59
尝试在加载视图后构造您的位置管理器。换言之,改变:
let locationManager = CLLocationManager()至
let locationManager : CLLocationManager!然后将其添加到viewDidLoad中。
locationManager = CLLocationManager()我已经看到了在初始化LocationManager的基础上构造UIViewController的奇怪行为。
发布于 2017-02-11 08:45:52
在测试信标测距时,我下载了多个忘记卸载的应用程序。在我卸载了所有与信标相关的应用程序并重新安装了所需的应用程序之后,我就能够让测距信标工作了。
https://stackoverflow.com/questions/39638067
复制相似问题