我使用的"[self.manager retrievePeripherals:[NSArray arrayWithObject:(id)aPeripheral.UUID]];”
工作正常,但在IOS7中已弃用。我发现我必须使用“retrievePeripheralsWithIdentifiers
”。但我无法弄清楚哪个是新函数的正确语法。任何人都可以请翻译
"[self.manager retrievePeripherals:[NSArray arrayWithObject:(id)aPeripheral.UUID]];”
到新函数“retrievePeripheralsWithIdentifiers”。
// Invoked when the central discovers heart rate peripheral while scanning.
- (void) centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)aPeripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
{
NSMutableArray *peripherals = [self mutableArrayValueForKey:@"heartRateMonitors"];
if(![self.heartRateMonitors containsObject:aPeripheral])
[peripherals addObject:aPeripheral];
// Retrieve already known devices
[self.manager retrievePeripherals:[NSArray arrayWithObject:(id)aPeripheral.UUID]];
}
答案 0 :(得分:0)
最后我可以解决它,希望它有所帮助。
// Invoked when the central discovers heart rate peripheral while scanning.
- (void) centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)aPeripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
{
[self.manager retrievePeripheralsWithIdentifiers:@[[CBUUID UUIDWithString:@"180D"]]];
NSLog(@"centralManager didDiscoverPeripheral -> Discovered: %@", aPeripheral.name);
if (aPeripheral) {
[self stopScan];
_peripheral = aPeripheral;
[_manager connectPeripheral:self.peripheral
options:[NSDictionary dictionaryWithObject:
[NSNumber numberWithBool:YES]
forKey:
CBConnectPeripheralOptionNotifyOnDisconnectionKey]];
}
}