【问题标题】:IOS received notification when not connected bluetooth device is no longer available未连接蓝牙设备不再可用时 IOS 收到通知
【发布时间】:2013-06-09 15:33:04
【问题描述】:

我知道如何使用scanForPeripheralsWithServices 接收新的可用外围设备通知,并使用其回调didDiscoverPeripheral 填充UITableView 列表。

但是,当未连接蓝牙设备不再可用时如何接收通知?

/****************************************************************************/
/*                              Discovery                                   */
/****************************************************************************/
- (void) startScanningForUUIDString:(NSString *)uuidString
{
    NSArray         *uuidArray  = [NSArray arrayWithObjects:[CBUUID UUIDWithString:uuidString], nil];
    NSDictionary    *options    = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];

    [centralManager scanForPeripheralsWithServices:uuidArray options:options];
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    if (![foundPeripherals containsObject:peripheral]) {
        [foundPeripherals addObject:peripheral];
        [discoveryDelegate discoveryDidRefresh];
    }
}

【问题讨论】:

    标签: iphone ios core-bluetooth bluetooth-lowenergy


    【解决方案1】:

    我认为您想知道的原因是因为您想刷新 foundPeripherals 数组并正确更新 UI?好吧,由于您当前与设备没有联系,因此无法知道设备何时移开或靠近。您的解决方案是这样的:启动一个 NSTimer 来清除您的 foundPeripherals 并在它触发时再次开始发现。如果您在新发现中看到它,它仍然存在,您应该重新添加到 foundPeripherals。不然就没了。

    【讨论】:

    • 感谢您的回答。我已经这样做了。当设备不再可用时无法通知我,我有点惊讶。
    • 是的,不过可能是 ios 7 ..希望
    • 不知道IOS7是否实现了这个功能?
    • 对于此解决方案,您是否必须将选项“CBCentralManagerScanOptionAllowDuplicatesKey”设置为“是”? iOS 7 似乎也没有替代解决方案。
    猜你喜欢
    • 1970-01-01
    • 2010-10-21
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    相关资源
    最近更新 更多