A iBeacon Detector
- 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 | |
- NSLocationAlwaysUsageDescription
func checkAvailable() -> Bool {
if !CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
return false
}
if CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedAlways {
locationManager.requestAlwaysAuthorization()
}
return true
}guard let beaconUuid = UUID(uuidString: defaultUuid) else {
throw AppError(msg: "Invalid UUID")
}
let r = CLBeaconRegion(proximityUUID: beaconUuid, identifier: beaconId)
r.notifyOnExit = true
r.notifyOnEntry = true
r.notifyEntryStateOnDisplay = true
locationManager.startMonitoring(for: r)if !CLLocationManager.isRangingAvailable() {
return
}
locationManager.startRangingBeacons(in: region)locationManager.delegate = self
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
if beacons.count == 0 {
return
}
// parse the nearest one
parseBeacon(beacons[0], in: region)
}class CLBeacon : NSObject, NSCopying, NSSecureCoding {
var proximityUUID: UUID { get }
var major: NSNumber { get }
var minor: NSNumber { get }
var proximity: CLProximity { get }
var accuracy: CLLocationAccuracy { get }
var rssi: Int { get }
}