无法通过蓝牙将第三台设备连接到AppleTV

时间:2015-09-19 01:59:54

标签: ios objective-c bluetooth-lowenergy core-bluetooth tvos

我正在设置一个应用程序,通过蓝牙使用最多3个外部iPhone作为控制器。一切似乎都设置正确,前两个设备将正常连接,但一旦我尝试连接第三个iPhone,它就拒绝连接到它。

我的代码有限制或有问题吗?为什么第三个设备无法连接?

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSLog(@"Found peripheral: %@\n\twith data: %@", peripheral, advertisementData);

    //Check advertisement data for UUID
    CBUUID* serviceUUID = [CBUUID UUIDWithString:serviceUUIDString];
    NSArray* serviceUUIDs = [advertisementData valueForKey:CBAdvertisementDataServiceUUIDsKey];

    if([serviceUUIDs containsObject:serviceUUID])
    {
        //Valid controller, connect
        NSLog(@"Valid peripheral, connecting...");
        [self.btManager connectPeripheral:peripheral options:nil];

        //Save peripheral as player #x
        if(!self.player2)
        {
            self.player2 = peripheral;
        }
        else if(!self.player3)
        {
            self.player3 = peripheral;
        }
        else if(!self.player4)
        {
            self.player4 = peripheral;

            //Maximum players connected
            //Stop scanning
            [self.btManager stopScan];
        }
        else
        {
            //Maximum players connected
            //Ignore and stop scanning
            [self.btManager stopScan];
            return;
        }

        if(!_peripherals)
            _peripherals = [NSMutableArray arrayWithCapacity:0];

        [_peripherals addObject:peripheral];
    }
}

我正在存储外围设备并调用连接,但它实际上从未完成连接。我尝试以不同的顺序连接每个iPhone,如果它们是播放器2或播放器3,则所有3个设备将连接,但播放器4拒绝连接。

编辑:

我断开所有连接的设备,播放器4设备将连接。

0 个答案:

没有答案