0 Replies
      Latest reply: Sep 18, 2015 7:11 PM by MathNerdProductions RSS
      MathNerdProductions Level 1 Level 1 (0 points)

        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.