iOS 设备作为 iBeacon,为什么它不起作用?

iOS device as an iBeacon, why is it not working?

我正在尝试制作一个 iOS 应用程序,它使用 PeripheralManager 将 UUID 广播到 Central。

我觉得我的 permissions and Capabilities 没问题, 但是用中央搜索还是找不到我的信标

有什么我忘了的吗?

import UIKit
import CoreBluetooth
import CoreLocation

class ViewController: UIViewController, CBPeripheralManagerDelegate {

var localBeacon: CLBeaconRegion!
var beaconPeripheralData: NSDictionary!
var peripheralManager: CBPeripheralManager!


override func viewDidLoad() {
    super.viewDidLoad()
    initLocalBeacon()

}

func initLocalBeacon() {

    if localBeacon != nil {
        stopLocalBeacon()
    }

    let localBeaconUUID = "e276c0c0-d740-52e8-b778-9ae6e514269e"
    let localBeaconMajor: CLBeaconMajorValue = 1
    let localBeaconMinor: CLBeaconMinorValue = 1

    let uuid = UUID(uuidString: localBeaconUUID)!
    localBeacon = CLBeaconRegion(proximityUUID: uuid, major: localBeaconMajor, minor: localBeaconMinor, identifier: "Kristers Beacon")

    beaconPeripheralData = localBeacon.peripheralData(withMeasuredPower: -45)

    peripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)


}

func stopLocalBeacon() {

    peripheralManager.stopAdvertising()
    peripheralManager = nil
    beaconPeripheralData = nil
    localBeacon = nil
}

func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {


    if peripheral.state == .poweredOn {
        peripheralManager.startAdvertising(beaconPeripheralData as! [String: AnyObject]!)

    } else if peripheral.state == .poweredOff {
        stopLocalBeacon()
    }
}


}

问题出在蓝牙扫描仪上,它没有搜索特定的 Proximity UUID。 Locate beacon 应用程序 很棒,谢谢 paul