【发布时间】:2013-10-09 05:40:12
【问题描述】:
我在将我的 CoreBluetooth 代码从 iOS 6 更新到 iOS 7 时遇到问题。我可以扫描外围设备并建立连接,但是,我无法使用 iOS 7 中提供的新 CoreBluetooth 方法重新连接外围设备。这里是看看我是如何尝试完成重新连接的:
- (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 设备,但无济于事。
提前致谢! 听得见
【问题讨论】:
标签: objective-c iphone ipad ios7 core-bluetooth