swift - iOS 应用无法识别我的信标

标签 swift swift2 xcode7 ibeacon ios9.3

我上周才发现 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/

相关文章:

ios - Storyboard中按钮上的文本和模拟器中未显示的按钮?

ios - 如何使用以下完成处理程序调用函数?

ios - 我的单元格正在复制以应用我对在线数据库所做的更改

swift - 如何检测 NSMenu 是否关闭?

ios - 并非所有单元格都加载到表格 View 中,而是出现空白屏幕。 Xcode/Swift

c - 用户创建的警告在 XCode 7.1 中不再起作用。还有其他选择吗?

swift - 如何快速将自身转换为UnsafeMutablePointer <Void>类型

swift - 快速查询私有(private)数据库以获取用户详细信息

ios - 如何在 ios swift 中使用 nsurlconnection 从 FTP 服务器下载包含多个文件的完整目录?

ios - Swift 2 api调用比其他函数运行时间更长