2

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);

    //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];
    }
}

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.

Edit:

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

Community
  • 1
  • 1
Liftoff
  • 24,717
  • 13
  • 66
  • 119
  • According to other questions on SO [here](http://stackoverflow.com/questions/17274506/how-many-devices-we-can-pair-via-bluetooth-to-iphone) and [here](http://stackoverflow.com/questions/13469502/maximum-number-of-peripherals-on-corebluetooth/13654052#13654052), iPhone can have 10 devices connect to it. Are you trying to connect iPhones to a AppleTV? – Black Frog Sep 19 '15 at 02:21
  • It sure seems that if iPhones can connect 10 or 20 devices without any issue, the brand new Apple TV should be able to connect at least 3. – Liftoff Sep 19 '15 at 02:29
  • Do you have the latest AppleTV hardware? Because the limitation you may be currently experiencing could be hardware related. Also it could be tvOS beta issue. You should try your question on Apple Dev Forum. And also open a bug report with Apple. – Black Frog Sep 19 '15 at 03:03
  • @blackfrog I am working with the Apple TV Dev Kit with the latest beta OS. I will open a bug report. – Liftoff Sep 19 '15 at 03:44
  • That would be a huge mistake if their SDK or their BLE Chip doesn't allow to connect to more than 2 devices. Keep us inform with the bug report ;) – Larme Sep 21 '15 at 08:25
  • Response from Apple: "This issue behaves as intended based on the following: This is limited by the bluetooth bandwidth. We are now closing this bug report. If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information. Please be sure to regularly check new Apple releases for any updates that might affect this issue." – Liftoff Sep 21 '15 at 21:10

0 Answers0