Connecting 3 iPhones via CoreBluetooth

I am setting up an app that uses up to 3 external iPhones as controllers via Bluetooth. Everything seems to be set up properly, and the first 2 devices will connect properly, but once I try to connect a third iPhone, it refuses to connect to it.


Is there some limit or some problem with my code? Why can't the third device connect?



- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSLog(@"Found peripheral: %@\n\twith data: %@", peripheral, advertisementData);
   
    /
    CBUUID* serviceUUID = [CBUUID UUIDWithString:serviceUUIDString];
    NSArray* serviceUUIDs = [advertisementData valueForKey:CBAdvertisementDataServiceUUIDsKey];
   
    if([serviceUUIDs containsObject:serviceUUID])
    {
        /
        NSLog(@"Valid peripheral, connecting...");
        [self.btManager connectPeripheral:peripheral options:nil];
       
        /
        if(!self.player2)
        {
            self.player2 = peripheral;
        }
        else if(!self.player3)
        {
            self.player3 = peripheral;
        }
        else if(!self.player4)
        {
            self.player4 = peripheral;
        }
        else
        {
            return;
        }
       
        if(!_peripherals)
            _peripherals = [NSMutableArray arrayWithCapacity:0];
       
        [_peripherals addObject:peripheral];
    }
}



I am storing the peripheral and calling the connection, but it never actually completes the connection. I have tried connecting each of the iPhone in different orders and all 3 devices will connect if they are player 2 or player 3, but player 4 refuses to connect.


The second I disconnect any of the connected devices, the player 4 device will connect.

Replies

Sounds like Core Bluetooth is limited the same way as the MFi controllers?


"tvOS apps can use the remote and up to two MFI game controllers."

https://forums.developer.apple.com/thread/17937

That just seems strange considering that iPhones can connect upwards of 10 bluetooth peripherals at once. You'd think the new Apple TV would be able to handle 3, especially when there are apps being made right now that advertise 4 players.

I believe those games are using Bonjour services rather than BLE, I have only been able to get a max of 3 BLE devices connected at once

CoreBluetooth only allows 2 accessories on tvOS.


If you want to attach more devices, you may want to look at using Bonjour over the Wifi or ethernet network.

hi,


does TVos allow a remote and iPhone as 2nd controller to play multiplayer game ?


If so, how do we detect the second player input?

I've developed an open-source framework that is designed to make it easy to create an iOS-based game controller that appears as a hardware-based controller: https://github.com/robreuss/VirtualGameController It wraps Game Controller and uses NSNetService for connecting software-based controllers, which gets around the Core Bluetooth limitations by communicating over WiFi.