【发布时间】:2014-04-04 00:20:14
【问题描述】:
我正在测试一个应用来显示附近的蓝牙设备。目前,代码很简单如下:
- (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 是“我试图发现的设备能否被发现?”尝试使用itunes.apple.com/us/app/lightblue-bluetooth-low-energy/… 并告诉我们您是否真的可以看到这些设备。
-
显然它没有发现预期的设备。您所说的“我试图发现的设备是否可以被发现?”是什么意思?如果我的 macbook 可以发现我的 iphone 和 ipad,为什么不能反过来或互相发现?
-
所以我的理解是您正试图从您的 iDevices 中发现您的 macbook?正确的?好吧,只有当您打开蓝牙设置(系统偏好设置 -> 蓝牙)时,您的 macbook 才能被发现。如果您仔细查看它们的蓝牙设置窗口,它会显示“现在可以发现为“您的 macbook 的名称””。否则,您的 iDevices 将无法发现您的 macbook。
-
我已经在打开蓝牙设置时对其进行了测试。 iphone 没有发现 macbook 和 ipad
-
您的问题解决了吗?