7

を使用して iOS アプリケーションから Apple TV 4 Siri Remote を検出することは可能CoreBluetoothですか? Apple TV は検出できますが、Siri Remote を検出できません。Siri Remoteは Bluetooth 4.0 を使用しているため、検出可能であると想定しています。理想的には、すでに Apple TV とペアリングされている場合でも、Siri Remote を検出したいと考えています。

単に 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