我在更新我的CoreBluetooth代码从iOS 6到iOS 7时遇到问题。我可以扫描外围设备并建立连接,但是,我无法使用提供的新CoreBluetooth方法重新连接外设内的iOS 7.下面来看看我如何努力实现重新连接:iOS 7 CoreBluetooth retrievePeripheralsWithIdentifiers not retrieve
- (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设备,但无济于事。
在此先感谢! audible
我想知道如果你能帮助我与我的代码转换为retrievePeripheralsWithIdentifiers - (空)centralManager:(CBCentralManager *) didDiscoverPeripheral中心:(CBPeripheral *)aPeripheral advertisementData:(NSDictionary的*)advertisementData RSSI:(NSNumber *)RSSI { NSMutableArray * peripherals = [self mutableArrayValueForKey:@“heartRateMonitors”]; if(![self.heartRateMonitors containsObject:aPeripheral]) [peripherals addObject:aPeripheral]; [self.manager retrievePeripherals:[NSArray arrayWithObject:(id)aPeripheral.UUID]]; } –