【发布时间】:2016-07-10 06:04:01
【问题描述】:
我上周刚刚发现了 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)
【问题讨论】:
标签: swift swift2 xcode7 ibeacon ios9.3