bluetooth - IOS 蓝牙搜不到设备

 榴莲味蛋筒 发布于 2022-11-04 10:00

RT,不知道为什么搜不到设备,我用lightBlue也搜不到设备,然后我自己写的demo用ipad测试也是搜不到设备,求解,判断蓝牙是否打开那些方法都写了

  • (CBCentralManager *)mgr
    {
    if (!_mgr) {
    // 创建中心设备管理者,用来管理中心设备
    self.mgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    }
    return _mgr;
    }
  • (void)viewDidLoad
    {
    [super viewDidLoad];

    // 扫描外设
    [self.mgr scanForPeripheralsWithServices:nil options:nil];

}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{

 NSLog(@"搜到的peripheralName:%@----%@",peripheral,peripheral.name);

}
-(void)centralManagerDidUpdateState:(CBCentralManager *)central
{
switch (central.state)
{
case CBCentralManagerStatePoweredOn:
{
[self.mgr scanForPeripheralsWithServices:nil options:nil];

        NSLog(@"蓝牙已经打开");
    }
        break;

    default:
        NSLog(@"蓝牙没打开或设备不支持");
        break;
}

}

就这3个方法,我现在还在尝试能不能搜索到蓝牙,搜到再去考虑连接蓝牙
http://blog.csdn.net/pony_maggie/article/details/26740237这是我参考的demo

3 个回答
  • 你好我也是遇到同样的问题,iOS 蓝牙搜不到设备,imac和android机器都可以看到 iOS的蓝牙设备就是

    2022-11-07 14:03 回答
  • 你的设备都是bluetooth 4.0的设备吗?

    2022-11-07 14:24 回答
  • 可以的话放下代码,帮你调调 还有参考参考链接

    ——————————————————————————————————————————————————

    写好了,你的教程确实实现不了,可能iOS蓝牙的实现方式变过了,注意设置完代理,貌似现在scanForPeripheralsWithServices必须放在centralManagerDidUpdateState这里

    -(void)centralManagerDidUpdateState:(CBCentralManager *)central{
        switch (central.state) {
            case CBCentralManagerStatePoweredOn:
                [_manager scanForPeripheralsWithServices:nil options:nil];
                break;
            default:
                NSLog(@"不支持!!!");
                break;
        }
    }
    

    2022-11-07 14:28 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有