An iBeacon Broadcastor
- A
protocoldeveloped by Apple - A Bluetooth low energy (BLE) device as
Beacon - Beacon
broadcastsinformation
iPhone4Sor later- 3rd generation
iPador later - iPad Mini or later
- 5th generation
iPodtouch or later
| Preamble 1Byte |
Address 4Bytes |
Protocol Data Unit <=39Bytes |
CRC 3Bytes |
|
| Header 2Bytes |
Payload 0 ~ 37Bytes |
|||
| Field | Size |
|---|---|
| UUID | 16 bytes |
| Major | 2 bytes |
| Minor | 2 bytes |
| Store Location | San Francisco | Paris | London | |
|---|---|---|---|---|
| UUID | D9B9EC1F-3925-43D0-80A9-1E39D4CEA95C | |||
| Major | 1 | 2 | 3 | |
| Minor | Clothing | 10 | 10 | 10 |
| Housewares | 20 | 20 | 20 | |
| Automotive | 30 | 30 | 30 | |
- NSBluetoothPeripheralUsageDescription
override func viewDidLoad() {
super.viewDidLoad()
peripheralManager = CBPeripheralManager()
peripheralManager.delegate = self
}
extension BeaconBroadcaster: CBPeripheralManagerDelegate {
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
btEnable = false
switch peripheral.state {
case .poweredOff:
print("poweredOff")
case .poweredOn:
print("poweredOn")
btEnable = true
case .resetting:
print("resetting")
case .unauthorized:
print("unauthorized")
case .unsupported:
print("unsupported")
case .unknown:
print("unknown")
}
}
}let beaconUuid = UUID(uuidString: defaultUuid)!
let major: CLBeaconMajorValue = 94
let minor: CLBeaconMinorValue = 87
let beaconID = "tw.cowbjt.beacon"
let region = CLBeaconRegion(proximityUUID: beaconUuid, major: major, minor: minor, identifier: beaconID)
let peripheralData = region.peripheralData(withMeasuredPower: nil)
peripheralManager.startAdvertising(((peripheralData as NSDictionary) as! [String : Any]))peripheralManager.stopAdvertising()