Objective C- BLE device Manufacturers data comparison

六眼飞鱼酱① 提交于 2019-12-13 03:44:48

问题


I have a task of comparing Manufacturers data to a string to display the BLE devices .

-(void)centralManager:(CBCentralManager *):didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSString *manufac=[advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey];
    NSString *string=@"57394423 4334445 55";
    if([string isEqualToString:manufac])
       NSLog(@"yes it is the device");
    else
       NSLog(@"sorry not a device");
}

'manufac' when printed gives result as <57394423 4334445 55> which doesnot prove to be correct at any time. How can it be compared ? please help.


回答1:


The object returned by the CBAdvertisementDataManufacturerDataKey is an NSData object. You are assigning it to an NSString object which is wrong.

To get the UUID you could do the following:

NSData *manufacturer = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDBytes:manufacturer.bytes];

And then compare this UUID to the one you are searching for. If you need an actual NSString representation, use uuid.UUIDString.



来源:https://stackoverflow.com/questions/34942484/objective-c-ble-device-manufacturers-data-comparison

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!