1
我正在测试一个应用程序来显示附近的蓝牙设备。现在,代码简单如下:iOS蓝牙不发现设备
- (IBAction)scanForDevices:(id)sender
{
UIButton * btn = sender;
if(self.cManager.state != CBCentralManagerStatePoweredOn)
{
NSLog(@"CoreBluetooth is %s",[self centralManagerStateToString:self.cManager.state]);
}
if(!self.isSearching){
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[self.cManager scanForPeripheralsWithServices:nil options:options];
btn.titleLabel.text = @"Stop";
self.isSearching = YES;
}
else
{
btn.titleLabel.text = @"Search";
self.isSearching = NO;
}
}
#pragma mark - CBCentral Delegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
NSLog(@"Ready to discovery..");
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Receive periferal: %@", peripheral);
}
但每次我按下按钮执行scanForDevices时间,回调函数接到电话,但与外围空值。我不确定我的设备是否正常工作。在我的笔记本电脑上,我的iphone 4S(6.0.1)和ipad(7.1)都被发现,但不是来自iphone和ipad。
你必须从某个地方开始。问题#1是'我试图发现的设备可以被发现吗?'尝试使用https://itunes.apple.com/us/app/lightblue-bluetooth-low-energy/id557428110?mt=8并告诉我们您是否可以真正看到设备。 – bsarrazin
显然它没有发现预期的设备。 '我想要发现的设备可以被发现是什么意思?'如果我的MacBook可以发现我的iPhone和iPad,为什么不是其他方式或其他方式? – REALFREE
所以我的理解是,你试图从你的iDevices中发现你的macbook?正确?当你打开蓝牙设置(系统首选项 - >蓝牙)时,你的MacBook才能被发现。如果你仔细看看他们的蓝牙设置窗口,它会显示“现在可以发现”为你的macbook的名字“'”。否则,您的iBook设备将无法发现您的macbook。 – bsarrazin