原文网址:http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/73443.aspx
NSArray *keys = [advertisementData allKeys];
NSData *dataAmb, *dataObj; for (int i = 0; i < [keys count]; ++i) { id key = [keys objectAtIndex: i]; NSString *keyName = (NSString *) key; NSObject *value = [advertisementData objectForKey: key]; if ([value isKindOfClass: [NSArray class]]) { printf(" key: %s\n", [keyName cStringUsingEncoding: NSUTF8StringEncoding]); NSArray *values = (NSArray *) value; for (int j = 0; j < [values count]; ++j) { if ([[values objectAtIndex: j] isKindOfClass: [CBUUID class]]) { CBUUID *uuid = [values objectAtIndex: j]; NSData *data = uuid.data; if (j == 0) { dataObj = uuid.data; } else { dataAmb = uuid.data; } printf(" uuid(%d):", j); for (int j = 0; j < data.length; ++j) printf(" %02X", ((UInt8 *) data.bytes)[j]); printf("\n"); } else { const char *valueString = [[value description] cStringUsingEncoding: NSUTF8StringEncoding]; printf(" value(%d): %s\n", j, valueString); } } } else { const char *valueString = [[value description] cStringUsingEncoding: NSUTF8StringEncoding]; printf(" key: %s, value: %s\n", [keyName cStringUsingEncoding: NSUTF8StringEncoding], valueString); } }
谢谢,可是得出来得结果是
key: kCBAdvDataIsConnectable, value: 1
key: kCBAdvDataLocalName, value: SimpleBLEPeripheral
key: kCBAdvDataServiceUUIDs
uuid(0): FF F0
key: kCBAdvDataTxPowerLevel, value: 0
我想获取得广播数据还是读取不到。。。。
对于iOS设备,我是通过kCBAdvDataServiceUUIDs得到广播数据的。
Li Zongwu:
我也感觉广播数据应该是在advertisementData中的,可以里面就是没有kCBAdvDataServiceUUIDs这个键值。纠结。。。。不知道是不是那里面的程序不对,你的
-(void)centralManagerDidUpdateState:(CBCentralManager *)central
{....}这里面怎么定义的啊。。。
用我之前提供的代码,就可以得到kCBAdvDataServiceUUIDs这个key值,这个key值对应的就是广播里地所谓的数据了。