在 IOS7 中检测启用蓝牙的 iPhone 设备

2024-01-30

我在我的应用程序中使用核心蓝牙框架。

我知道如何扫描外围设备并从中获取值。(例如心率监视器)

但我想要的是检索支持 BLE 4.0 和蓝牙功能的周围 iPhone 设备列表。

我参考了下面的链接..

使用 IOBluetooth 框架 http://www.ggkf.com/osx/how-to-make-a-drop-down-list-of-available-bluetooth-devices-in-objective-c

使用 CoreBluetooth 获取外设而不是设备列表 https://stackoverflow.com/questions/13062096/how-to-display-the-supported-services-of-bluetooth-in-tableview-from-devicename

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

不知道苹果有没有提供这个..

任何建议或想法将不胜感激..

预先感谢..


尝试下面的代码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];

  }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 IOS7 中检测启用蓝牙的 iPhone 设备 的相关文章

  • UICollectionView 自动滚动到 IndexPath 处的单元格

    在加载集合视图之前 用户设置集合视图数组中的图像数量 所有单元格都不适合屏幕 我有 30 个单元格 但屏幕上只有 6 个 问题 如何在加载 UICollectionView 时自动滚动到具有所需图像的单元格 新的 编辑过的答案 将其添加到v
  • 无法构建 Saurik 的 ldid 实用程序

    当我执行此命令 make sh 时 我遇到这些错误 构建用于越狱调整开发的 ldid 实用程序 Bilals Mac ldid billy make sh g arch i386 arch x86 64 arch ppc arch armv
  • 如何使用 iPhone SDK 实现可滑动的图像堆栈(例如照片应用程序)?

    我想获取一堆图像 或者可能是一组用于下载图像的 URL 并以全屏方式显示它们 一次一个 使用 iPhone SDK 使用用户滑动来平滑地为堆栈中的下一个图像设置动画 Apple 的 Photo app 似乎可以做到这一点 此外 如果尚未检索
  • 在 Objective-C 中比较 2 个字符串

    我写了以下代码 if depSelectedIndice gt 1 comSelectedIndice gt 1 NSLog depart elemet d depSelectedIndice NSLog depart elemet d c
  • 使用 iOS 8 自定义键盘发送图像?

    我一直在为 iOS 8 开发自定义键盘 但在尝试使用键盘发送图像时偶然发现了一个问题 我做了一些研究 似乎没有一种简单的方法可以做到这一点UITextDocumentProxy因为只有NSStrings被允许 我是否忽略了使用自定义键盘发送
  • 使用 iPhone 中的地图视图读取当前位置名称

    我读取了当前位置的纬度和经度值 然后成功将该位置固定在 iPhone 中 现在我想使用这个纬度和经度值读取该地名 我使用以下代码来读取查找当前位置 void mapView MKMapView mapView1 didUpdateUserL
  • 在 WKWebView 中禁用放大手势

    我正在寻找一种方法来禁用 WKWebView 的 iOS 实现上的 捏合缩放 放大手势 OS X 有一个 magnification BOOL 属性 但在 iOS 上似乎不可用 WKWebView h if TARGET OS IPHONE
  • 在横向中自动调整 UITableCells 内容的大小

    在 UITableView 中 我通过 UILabels 将内容添加到单元格中 定义最佳尺寸 与单元格宽度允许的一样大 我注意到只有tableView contentSize width是可靠的 因为cell contentView bou
  • 如何知道我的应用程序使用了多少 iCloud 空间?

    有没有办法查看我的应用程序正在备份到 iCloud 的内容以及它消耗了多少内存 Settings gt iCloud gt Storage Backup gt Manage Storage将显示正在备份的总计内容 iOS 会备份位于应用程序
  • 带操作按钮的颤动本地通知

    我在我的 flutter 项目中尝试了 flutter 本地通知插件 它在简单通知上工作正常 但我需要带有操作按钮的通知功能 请帮助我或建议我实现此功能 不幸的是 flutter local notifications 插件尚不支持操作按钮
  • 在 OS X 上创建和使用静态库

    好的 我正在尝试创建一个 Cocoa 库 静态 并使用 但我不断收到错误 我创建了一个超基本的静态库 TSXLib 其中仅包含一个额外的类 import
  • 更改组织以使用 Xcode 9 在 iTunes Connect 上上传二进制文件

    我在 Xcode9 上配置了多个团队 当我尝试将二进制文件上传到 Xcode 9 上的 iTunes Connect 时 没有更改团队的选项 并且出现以下错误 ERROR ITMS 4088 来自苹果开发者论坛的解决方案 1 正常存档2 窗
  • 减少 CoreData 的调试输出?

    我正在开发一个使用 CoreData 的 iOS macOS 项目 它工作正常 但它会向控制台输出大量调试信息 这使得控制台无法使用 因为我的打印语句隐藏在所有与 CoreData 相关的内容中 我有一个非常简单的 CoreData 设置
  • 在 Objective C 的类方法中引用类本身

    我希望我没有跳过 ObjC 手册中的这一部分 但是是否可以从类的一个类方法中引用该类 就像在 PHP 中一样 您将使用 this 来引用当前实例 而 self 引用实例的类 this 的 ObjC 等价物将是 self 那么 PHP 的 s
  • UIPanGestureRecognizer 对坐标的限制

    我在主 UIView 中添加了一个子视图 称为panel 并且我向其中添加了gestureRecognizer 因为我希望它只能在Y轴上拖动并且只能在某些限制下 即160 300 超过300它不能拖动 我以这种方式实现了手势处理 IBAct
  • ios水平居中约束问题?

    I am having hard time in learning constraints auto layout in iOS I have used any width any height I have a storyboard sc
  • insertNewObjectForEntityForName:

    我使用 Xcode xcdatamodel 文件编辑器设置了一个实体 我创建了一个名为 Person 的实体 添加了一些属性 然后生成了一个 m 文件来表示它 一切都很好 现在 当我去编写一行代码时 例如 Person person Per
  • 在 iOS 7 Safari 中,如何区分通过边缘滑动与后退/前进按钮的 popstate 事件?

    在 iOS 7 Safari 中 现在有两种后退 前进导航方式 使用底部的传统后退 前进按钮箭头或从屏幕边缘滑动 我正在使用动画在 ajax 应用程序中的页面之间进行转换 但如果用户通过边缘滑动进行导航 我不想触发该转换 因为这本身就是一个
  • Xcode 8 / Swift 3:“UIViewController 类型的表达式?未使用”警告

    我有以下函数 它之前编译得很干净 但在 Xcode 8 中生成警告 func exitViewController navigationController popViewController animated true UIViewCon
  • UIView晃动动画

    我试图在按下按钮时使 UIView 摇动 我正在调整我找到的代码http www cimgf com 2008 02 27 core animation tutorial window shake effect http www cimgf

随机推荐