在IOS中的IOS7中检测启用了蓝牙的iPhone设备 [英] Detecting Bluetooth Enabled iPhone devices in IOS7 in IOS

查看:130
本文介绍了在IOS中的IOS7中检测启用了蓝牙的iPhone设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中使用Core Bluetooth Framework。

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)

但是我要检索的是支持BLE 4.0和Bluetooth Enabled的iPhone设备列表。

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

我提到了

使用IOBluetooth框架

使用CoreBluetooth获取外围设备而不是设备列表

 - (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
    }
}

我不知道Apple是否提供此功能。

I dont know whether Apple provides this or not..

任何建议或想法都会受到赞赏。

Any Suggestions or Ideas will be appreciated..

谢谢。.

推荐答案

尝试下面的代码 checkBluetoothAccess requestBluetoothAccess 方法

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

  }

这篇关于在IOS中的IOS7中检测启用了蓝牙的iPhone设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆