我正在使用本机应用程序来使用apple的iBeacon框架,并尝试在控制台上记录我附近所有bluetoooth设备的列表。我一直关注this tutorial但是当我运行应用程序时,没有任何内容打印到控制台。我的错误在哪里?
下面是我编写的视图控制器文件的完整细节:
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(uuidString: "852c0828-fe67-4dd7-b8ff-52852a66851e")! as UUID, major: 8008, minor: 1337, identifier: "Testing")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedWhenInUse) {
locationManager.requestWhenInUseAuthorization()
}
locationManager.startRangingBeacons(in: region)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
print(beacons)
print("hello")
}
}
在运行时没有任何内容打印到控制台,包括“你好”。
代码看起来不错。你确定你知道你的信标标识符并且它正在传输吗?
我会尝试使用现成的信标检测器应用程序,如Locate,以验证它可以看到你的灯塔。请注意,您必须在应用程序中配置信标UUID以进行检测。
其他一些提示:
<key>NSLocationWhenInUseUsageDescription</key><string>This app needs to access your location so it can tell when you are near a beacon.</string>