客观C- BLE设备制造商数据比较 [英] Objective C- BLE device Manufacturers data comparison
问题描述
我的任务是将制造商的数据与字符串进行比较以显示BLE设备.
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"在打印时给出的结果为< 57394423 4334445 55>,该结果在任何时候都不能证明是正确的. 怎么可以比较?请帮忙.
'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.
推荐答案
CBAdvertisementDataManufacturerDataKey
返回的对象是NSData
对象.
您正在将其分配给错误的NSString
对象.
The object returned by the CBAdvertisementDataManufacturerDataKey
is an NSData
object.
You are assigning it to an NSString
object which is wrong.
要获取UUID,您可以执行以下操作:
To get the UUID you could do the following:
NSData *manufacturer = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDBytes:manufacturer.bytes];
然后将该UUID与您要搜索的UUID进行比较.如果需要实际的NSString
表示形式,请使用uuid.UUIDString
.
And then compare this UUID to the one you are searching for. If you need an actual NSString
representation, use uuid.UUIDString
.
这篇关于客观C- BLE设备制造商数据比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!