@@ -39,7 +39,7 @@ @interface ESSBeaconScanner () <CBCentralManagerDelegate> {
3939 * Then, the next time we see a UID frame for that Eddystone, we can add the most recently seen
4040 * telemetry frame to the sighting.
4141 */
42- NSMutableDictionary *_deviceIDCache ;
42+ NSMutableDictionary *_tlmCache ;
4343
4444 /* *
4545 * Beacons we've seen already. If we see an Eddystone and notice that we've seen it before, we
@@ -63,7 +63,7 @@ @implementation ESSBeaconScanner
6363- (instancetype )init {
6464 if ((self = [super init ]) != nil ) {
6565 _onLostTimeout = 15.0 ;
66- _deviceIDCache = [NSMutableDictionary dictionary ];
66+ _tlmCache = [NSMutableDictionary dictionary ];
6767 _seenEddystoneCache = [NSMutableDictionary dictionary ];
6868 _beaconOperationsQueue = dispatch_queue_create (kBeaconsOperationQueueName , NULL );
6969 _centralManager = [[CBCentralManager alloc ] initWithDelegate: self
@@ -107,35 +107,51 @@ - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
107107
108108// This will be called from the |beaconsOperationQueue|.
109109- (void )centralManager : (CBCentralManager *)central
110- didDiscoverPeripheral : (CBPeripheral *)peripheral
111- advertisementData : (NSDictionary *)advertisementData
112- RSSI : (NSNumber *)RSSI {
113-
110+ didDiscoverPeripheral : (CBPeripheral *)peripheral
111+ advertisementData : (NSDictionary *)advertisementData
112+ RSSI : (NSNumber *)RSSI {
114113 NSDictionary *serviceData = advertisementData[CBAdvertisementDataServiceDataKey];
114+ NSData *beaconServiceData = serviceData[[ESSBeaconInfo eddystoneServiceID ]];
115+
116+ ESSFrameType frameType = [ESSBeaconInfo frameTypeForFrame: beaconServiceData];
115117
116118 // If it's a telemetry (TLM) frame, then save it into our cache so that the next time we get a
117119 // UID frame (i.e. an Eddystone "sighting"), we can include the telemetry with it.
118- ESSFrameType frameType = [ESSBeaconInfo frameTypeForFrame: serviceData];
119120 if (frameType == kESSEddystoneTelemetryFrameType ) {
120- _deviceIDCache[peripheral.identifier] = [ESSBeaconInfo telemetryDataForFrame: serviceData];
121- } else if (frameType == kESSEddystoneUIDFrameType ) {
121+ _tlmCache[peripheral.identifier] = beaconServiceData;
122+ } else if (frameType == kESSEddystoneURLFrameType ) {
123+ NSURL *url = [ESSBeaconInfo parseURLFromFrameData: beaconServiceData];
124+
125+ // Report the sighted URL frame.
126+ if ([_delegate respondsToSelector: @selector (beaconScanner:didFindURL: )]) {
127+ [_delegate beaconScanner: self didFindURL: url];
128+ }
129+ } else if (frameType == kESSEddystoneUIDFrameType
130+ || frameType == kESSEddystoneEIDFrameType ) {
122131 CBUUID *eddystoneServiceUUID = [ESSBeaconInfo eddystoneServiceID ];
123132 NSData *eddystoneServiceData = serviceData[eddystoneServiceUUID];
124133
125134 // If we have telemetry data for this Eddystone, include it in the construction of the
126135 // ESSBeaconInfo object. Otherwise, nil is fine.
127- NSData *telemetry = _deviceIDCache [peripheral.identifier];
136+ NSData *telemetry = _tlmCache [peripheral.identifier];
128137
129- ESSBeaconInfo *beaconInfo = [ESSBeaconInfo beaconInfoForUIDFrameData: eddystoneServiceData
130- telemetry: telemetry
131- RSSI: RSSI];
138+ ESSBeaconInfo *beaconInfo;
139+ if (frameType == kESSEddystoneUIDFrameType ) {
140+ beaconInfo = [ESSBeaconInfo beaconInfoForUIDFrameData: eddystoneServiceData
141+ telemetry: telemetry
142+ RSSI: RSSI];
143+ } else {
144+ beaconInfo = [ESSBeaconInfo beaconInfoForEIDFrameData: eddystoneServiceData
145+ telemetry: telemetry
146+ RSSI: RSSI];
147+ }
132148
133- if (beaconInfo != nil ) {
149+ if (beaconInfo) {
134150 // NOTE: At this point you can choose whether to keep or get rid of the telemetry data. You
135151 // can either opt to include it with every single beacon sighting for this beacon, or
136152 // delete it until we get a new / "fresh" TLM frame. We'll treat it as "report it only
137153 // when you see it", so we'll delete it each time.
138- [_deviceIDCache removeObjectForKey: peripheral.identifier];
154+ [_tlmCache removeObjectForKey: peripheral.identifier];
139155
140156 // If we haven't seen this Eddystone before, fire a beaconScanner:didFindBeacon: and mark it
141157 // as seen.
0 commit comments