7

是否可以使用 iOS 应用程序检测 Apple TV 4 Siri Remote CoreBluetooth?我能够检测到 Apple TV,但我无法检测到 Siri Remote。Siri Remote使用蓝牙 4.0 ,所以我假设它是可检测的。理想情况下,我想检测 Siri Remote,即使它已经与 Apple TV 配对。

只需能够检测到来自 Siri Remote 的任何信号/知道它在用户 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);
}
4

0 回答 0