-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBeaconAdvertisementUtil.m
36 lines (25 loc) · 1.13 KB
/
BeaconAdvertisementUtil.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "BeaconAdvertisementUtil.h"
@implementation BeaconAdvertisementUtil
- (id)initWithProximityUUID:(NSUUID *)proximityUUID major:(uint16_t)major minor:(uint16_t)minor measuredPower:(int8_t)power {
self = [super init];
if (self) {
self.proximityUUID = proximityUUID;
self.major = major;
self.minor = minor;
self.measuredPower = power;
}
return self;
}
- (NSDictionary *)beaconAdvertisement {
NSString *beaconKey = @"kCBAdvDataAppleBeaconKey";
unsigned char advertisementBytes[21] = {0};
[self.proximityUUID getUUIDBytes:(unsigned char *)&advertisementBytes];
advertisementBytes[16] = (unsigned char)(self.major >> 8);
advertisementBytes[17] = (unsigned char)(self.major & 255);
advertisementBytes[18] = (unsigned char)(self.minor >> 8);
advertisementBytes[19] = (unsigned char)(self.minor & 255);
advertisementBytes[20] = self.measuredPower;
NSMutableData *advertisement = [NSMutableData dataWithBytes:advertisementBytes length:21];
return [NSDictionary dictionaryWithObject:advertisement forKey:beaconKey];
}
@end