- (voID)retrIEvePeripheral:(Nsstring *)uuIDString{NSUUID *nsUUID = [[NSUUID UUID] initWithUUIDString:uuIDString];if(nsUUID){ NSArray *peripheralArray = [centralManager retrIEveperipheralsWithIDentifIErs:@[nsUUID]]; // Check for kNown peripherals if([peripheralArray count] > 0) { for(CBPeripheral *peripheral in peripheralArray) { NSLog(@"Connecting to Peripheral - %@",peripheral); [self connectPeripheral:peripheral]; } } // There are no kNown peripherals so we check for connected peripherals if any else { CBUUID *cbUUID = [CBUUID UUIDWithNSUUID:nsUUID]; NSArray *connectedPeripheralArray = [centralManager retrIEveConnectedperipheralsWithServices:@[cbUUID]]; // If there are connected peripherals if([connectedPeripheralArray count] > 0) { for(CBPeripheral *peripheral in connectedPeripheralArray) { NSLog(@"Connecting to Peripheral - %@",peripheral); [self connectPeripheral:peripheral]; } } // Else there are no available peripherals else { // No Dice! NSLog(@"There are no available peripherals"); } }}}
其中uuIDString是保存的外围设备UUID.
我总是得到没有可用外围设备的NSLog声明.我想我错过了一些非常明显的东西,有人可以指出我正确的方向.
另外,我已经阅读了有关CoreBluetooth iOS 7更新问题的其他帖子,并尝试重置BLE设备和iOS设备,但无济于事.
提前致谢!
听得见
这是不正确的方式:
Nsstring *uuIDString = [Nsstring stringWithFormat:@"%@",CFUUIDCreateString(NulL,(__brIDge CFUUIDRef)([peripheral IDentifIEr]))];
这是正确的方法(在我的场景中有效):
Nsstring *uuIDString = [Nsstring stringWithFormat:@"%@",[[peripheral IDentifIEr] UUIDString]];
根据Apple文档,NSUUID类与CoreFoundation的CFUUIDRef没有免费桥接,如下所述:
Note: The
NSUUID
class is not toll-free brIDged with CoreFoundation’sCFUUIDRef
. Use UUID strings to convert betweenCFUUID
andNSUUID
,if needed. TwoNSUUID
objects are not guaranteed to be comparable by pointer value (asCFUUIDRef
is); useisEqual:
to compare twoNSUUID
instances.
对于那些喜欢直观表达我这意味着什么的人来说,这是一个例子:)
控制台中打印的外围设备信息:
<CBPeripheral: 0x14699430 IDentifIEr = DD2468AB-1865-B926-7FA4-AE3755D479D8,name = "IDYNAMO EMV-A27F",state = disconnected>
将Peripheral的标识符转换为Nsstring的错误方法产生:
1865B926-7FA4-AE37-55D4-79D800000000
将Peripheral的标识符转换为Nsstring的正确方法产生:
DD2468AB-1865-B926-7FA4-AE3755D479D8
我希望这可以帮助某人完成他们的BLE旅程,如果我错了,我可以随时纠正我,因为我还在学习这些东西.
谢谢!
听得见
总结以上是内存溢出为你收集整理的objective-c – iOS 7 CoreBluetooth retrievePeripheralsWithIcentifiers没有检索全部内容,希望文章能够帮你解决objective-c – iOS 7 CoreBluetooth retrievePeripheralsWithIcentifiers没有检索所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)