Detecting Bluetooth Enabled iPhone devices in IOS7 in IOS

夙愿已清 提交于 2019-12-02 02:54:15

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

  }

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!