是否可以使用CoreBluetooth
从iOS应用程序中检测Apple TV 4 Siri Remote?我能够检测到Apple TV,但我没有运气检测到Siri遥控器。 Siri Remote使用蓝牙4.0,因此我假设它是可检测的。理想情况下,我想检测Siri Remote,即使它已经与Apple TV配对了。
只需能够检测来自Siri遥控器的任何信号/知道用户iPhone附近的信息就在我之后。
#import "ViewController.h"
@import CoreBluetooth;
@interface ViewController () <CBPeripheralDelegate, CBCentralManagerDelegate>
@end
@implementation ViewController {
CBCentralManager *btManager;
}
-(void)viewDidLoad {
[super viewDidLoad];
btManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
#pragma mark - CBCentralManagerDelegate Methods
-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *, id> *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(@"peripheral name: %@", peripheral.name);
NSLog(@"peripheral services: %@", peripheral.services);
NSLog(@"peripheral identifier: %@", peripheral.identifier);
NSLog(@"peripheral state: %ld", (long)peripheral.state);
NSLog(@"RSSI: %@ \n\n", RSSI);
}
-(void)centralManagerDidUpdateState:(CBCentralManager *)central {
NSString *nsLogMessage;
switch (central.state) {
case CBCentralManagerStateUnknown: {
nsLogMessage = [NSString stringWithFormat:@"State unknown, update imminent."];
break;
}
case CBCentralManagerStateResetting: {
nsLogMessage = [NSString stringWithFormat:@"The connection with the system service was momentarily lost, update imminent."];
break;
}
case CBCentralManagerStateUnsupported: {
nsLogMessage = [NSString stringWithFormat:@"The platform doesn't support Bluetooth Low Energy"];
break;
}
case CBCentralManagerStateUnauthorized: {
nsLogMessage = [NSString stringWithFormat:@"The app is not authorized to use Bluetooth Low Energy"];
break;
}
case CBCentralManagerStatePoweredOff: {
nsLogMessage = [NSString stringWithFormat:@"Bluetooth is currently powered off."];
break;
}
case CBCentralManagerStatePoweredOn: {
nsLogMessage = [NSString stringWithFormat:@"Bluetooth is currently powered on and available to use."];
NSDictionary *scanningOptions = @{CBCentralManagerScanOptionAllowDuplicatesKey: @YES};
[btManager scanForPeripheralsWithServices:nil options:scanningOptions];
break;
}
}
NSLog(@"%@", nsLogMessage);
}