2
votes

I am using Core Bluetooth Framework in my app.

I know how to scan for peripherals and getting values from it.(like Heart Rate Monitor)

But what I want is to retrieve the surrounding iPhone Devices list that supports BLE 4.0 and Bluetooth Enabled ones.

I referred below links..

Uses IOBluetooth Framework

Uses CoreBluetooth For Getting Peripherals not the Devices List

 - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    // I'm not sure how to make this work

    NSLog (@"Discovered peripheral: %@", [peripheral name]);
    [self.list addObject:peripheral.name]; // add peripheral name to foundarray
    NSLog (@"UUID peripheral: %@", [peripheral UUID]);

    NSLog (@"peripheral services before connected: %@", [peripheral services]);

    NSLog(@"adversting data %@",[NSString stringWithFormat:@"%@",[advertisementData description]]);

    NSLog(@"foundArray is %@", self.list);
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    NSLog(@"Central manager's state is updated to: %@", central);
    if(central.state == CBCentralManagerStatePoweredOn)
    {
        //okay your good to go and can now scan
    }
    else
    {
        //Unable to use CentralManager methods so print out the central.state and find out why
    }
}

I dont know whether Apple provides this or not..

Any Suggestions or Ideas will be appreciated..

Thank In Advance..

2
BLE is supported since iPhone 4S and above, iPad 3 and above. You won't get the list by code. Anyway, seeing CBCentralManager state should give you if the device supports BLE or not (CBCentralManagerStateUnsupported).Larme

2 Answers

2
votes

Try below code checkBluetoothAccess and requestBluetoothAccess method

 - (void)checkBluetoothAccess {

          if(!self.cbManager) {
               self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
          }

       /*
            We can ask the bluetooth manager ahead of time what the authorization status is for our bundle and take the appropriate action.
      */

         CBCentralManagerState state = [self.cbManager state];

        if(state == CBCentralManagerStateUnknown) {
              [self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"UNKNOWN", @"")];
        }
       else if(state == CBCentralManagerStateUnauthorized) {
              [self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"DENIED", @"")];
        }
    else {
              [self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"GRANTED", @"")];
      }
}


- (void)requestBluetoothAccess {

      if(!self.cbManager) {
              self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
        }

    /*
            When the application requests to start scanning for bluetooth devices that is when the user is presented with a consent dialog.
    */

    [self.cbManager scanForPeripheralsWithServices:nil options:nil];

  }
1
votes

You can only retrieve the surrounding iOS devices that support Bluetooth 4.0 if they are also advertising a specific service to identify them. You can't just see all iOS devices that are powered on and nearby. If they are advertising, you can just scan for nil and that will return the advertisement packets being seen.

Note: if you care about retrieving BLE devices currently connected from other apps, you can use the retrieveConnectedPeripheralsWithServices: method.