首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法连接ios 8中的蓝牙设备,即使是现有的代码,也找不到蓝牙和它在ios 7上工作的主要内容。

无法连接ios 8中的蓝牙设备,即使是现有的代码,也找不到蓝牙和它在ios 7上工作的主要内容。
EN

Stack Overflow用户
提问于 2014-09-27 11:34:29
回答 1查看 391关注 0票数 1

连接像ios 8中的腕带这样的蓝牙设备,甚至连现有的代码都找不到蓝牙,而且它在ios 7..my代码上工作得很好的主要问题,就像我建议我在ios 8中为蓝牙做任何改变一样。

代码语言:javascript
复制
-(void)connecttodevice { 
     // Scan for all available CoreBluetooth LE devices 
     NSArray *services = @[[CBUUID UUIDWithString:info_UUID],[CBUUID UUIDWithString:info_UUID_service],[CBUUID UUIDWithString:BAND_SERVICE_INFO]]; 
     NSLog(@"device connting....."); 
     CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; 
     [centralManager scanForPeripheralsWithServices:services options:nil]; 
     self.centralManager = centralManager; 
 } 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-27 12:01:38

您的问题是在创建scanForPeripheralsWithServices之后立即调用CBCentralManager,而不是像centralManagerDidUpdateState委托中指出的那样等待中央管理器处于开机状态。

代码语言:javascript
复制
- (void)centralManagerDidUpdateState:(CBCentralManager *)central

     if (central.state == CBCentrallManagerStatePoweredOn {
        NSArray *services = @[[CBUUID UUIDWithString:info_UUID],[CBUUID UUIDWithString:info_UUID_service],[CBUUID UUIDWithString:BAND_SERVICE_INFO]]; 
        NSLog(@"device connting....."); 
        [central scanForPeripheralsWithServices:services options:nil];
     }
}

在iOS 7中,在指示启用状态之前启动扫描,在控制台上发出警告。在iOS 8中,它不启动扫描。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26074216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档