我在更新我的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]]; } –