我上周才发现 iBeacon,我想试试看。我在亚马逊上买了这个信标。 https://www.amazon.com/gp/product/B010Q2PUGA/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 使用 Light Blue 应用程序,我能够读取信标信息(UUID、Major、Minor 等),因此我知道信标正在广播。 按照本教程,我制作了一个应用程序来熟悉信标编程。 (使用我的 UUID)代码有一个小改动,由于 swift 版本,我不得不将 println 更改为打印。 https://willd.me/posts/getting-started-with-ibeacon-a-swift-tutorial 尽管如此,我的应用程序似乎无法识别我的信标。在我的日志/调试区域中,我只看到:
[]
[]
[]
我的代码是:
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "8EBB5704-9697-02C9-D073-BF9162B72D7B")!, identifier: "iBeacon-6713")
// let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "8EBB5704-9697-02C9-D073-BF9162B72D7B")!, major: 11046, minor: 11047, identifier: "ibeacon")
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self;
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse) {
locationManager.requestWhenInUseAuthorization()
}
locationManager.startRangingBeaconsInRegion(region)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
// print(beacons)
// }
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
print(beacons)
}
}
xcode:版本 7.3.1 (7D1014)
OS X El Capitan:版本 10.11.5 (15F34)
iOS: 版本 9.3.2(13F69)
Apple Swift 版本 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
最佳答案
我怀疑 8EBB5704-9697-02C9-D073-BF9162B72D7B 不是信标的 Proximity UUID。 LightBlue 将为蓝牙设备显示许多不同的 UUID,并非所有 UUID 都是 ProximityUUID。与任何 iOS 应用程序一样,LightBlue 必须知道 PriximityUUID 才能使用 CoreLocation 检测信标。如果没有,它仍然可以使用 CoreBluetooth 检测蓝牙传输,但它将无法读取 iBeacon 标识符。这可能就是正在发生的事情。
您需要找出设备的 ProximityUUID。如果您不能按照制造商的说明执行此操作,则可以使用带有 Locate 的 Android 设备。应用程序,它可以在不知道预先知道标识符的情况下读取 iBeacon UUID。 iOS 设备无法做到这一点。
关于swift - iOS 应用无法识别我的信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38289116/