iOS蓝牙低能量ANCS明显';三次打击,你';重新退出';

iOS蓝牙低能量ANCS明显';三次打击,你';重新退出';,ios,objective-c,bluetooth-lowenergy,core-bluetooth,ancs,Ios,Objective C,Bluetooth Lowenergy,Core Bluetooth,Ancs,我们有一个订阅ANCS的可扩展外围设备。它还托管一些我们的应用程序连接的自定义服务 由于ANCS,必须在设置应用程序中连接到外围设备(xxx)。 因此,我们在应用程序中没有任何设施可用于启动BLE连接。 这也保持了UseEx的清洁度,减少了“角落案例” 用户可以在设置应用程序中进行连接。 然后,如果外围设备超出范围,iOS将自动重新连接一次 然而,客户发现,在离开房间后,外围设备往往无法重新连接 我们只能将BLE外围设备放在离iPhone大约15米远的金属盒中,才能可靠地再现这一点。通过以正确的

我们有一个订阅ANCS的可扩展外围设备。它还托管一些我们的应用程序连接的自定义服务

由于ANCS,必须在设置应用程序中连接到外围设备(xxx)。 因此,我们在应用程序中没有任何设施可用于启动BLE连接。 这也保持了UseEx的清洁度,减少了“角落案例”

用户可以在设置应用程序中进行连接。 然后,如果外围设备超出范围,iOS将自动重新连接一次

然而,客户发现,在离开房间后,外围设备往往无法重新连接

我们只能将BLE外围设备放在离iPhone大约15米远的金属盒中,才能可靠地再现这一点。通过以正确的速度打开和关闭案例,我们可以在10秒钟左右的时间内引发一系列失败的ANCS连接请求

以下是一些设备控制台日志,显示由于信号丢失而导致的第一次连接失败

Mar 18 16:38:05 afes-iPhone BTLEServer[107] <Notice>: (Note ) Central "xxx" is now subscribed to characteristic "ANCS Data Source"
Mar 18 16:38:07 afes-iPhone BTServer[68] <Error>: Core       Connection timed out to device "xxxxxxx"
Mar 18 16:38:07 afes-iPhone BTLEServer[107] <Notice>: (Note ) Peripheral "xxx" is now disconnected: Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo=0x14528470 {NSLocalizedDescription=The connection has timed out unexpectedly.}
Mar 18 16:38:07 afes-iPhone BTLEServer[107] <Notice>: (Note ) Connecting peripheral "xxx"...
Mar 18 16:38:07 afes-iPhone BTLEServer[107] <Notice>: (Note ) Central "xxx" is now unsubscribed from characteristic "ANCS Notification Source"
Mar 18 16:38:07 afes-iPhone BTLEServer[107] <Notice>: (Note ) Central "xxx" is now unsubscribed from characteristic "ANCS Data Source"
Mar 18 16:38:08 afes-iPhone BTLEServer[107] <Notice>: (Note ) Peripheral "xxx" is now connected
Mar 18 16:38:08 afes-iPhone Preferences[164] <Warning>: (Warn ) CoreBluetooth: API MISUSE: <CBPeripheral: 0x14da8170, identifier = xxxxxx, name = xxx, state = disconnected> can only accept commands while in the connected state
....
Mar 18 16:38:09 afes-iPhone BTServer[68] <Error>: Core       Connection timed out to device "xxxxxxxxx"
Mar 18 16:38:09 afes-iPhone BTLEServer[107] <Notice>: (Note ) Peripheral "xxx" is now disconnected: Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo=0x1453daf0 {NSLocalizedDescription=The connection has timed out unexpectedly.}
Mar 18 16:38:09 afes-iPhone BTLEServer[107] <Notice>: (Note ) Connecting peripheral "xxx"...
Mar 18 16:38:09 afes-iPhone BTLEServer[107] <Notice>: (Note ) Peripheral "xxx" did not use any built-in service, strike #1
3月18日16:38:05 afes iPhone BTLEServer[107]:(注)中央“xxx”现在订阅了特色“ANCS数据源”
3月18日16:38:07 afes iPhone BTServer[68]:与设备“xxxxxxx”的核心连接超时
3月18日16:38:07 afes iPhone BTLEServer[107]:(注意)外围设备“xxx”现在已断开连接:Error Domain=CBErrorDomain Code=6“连接意外超时。”UserInfo=0x14528470{NSLocalizedDescription=连接意外超时。}
3月18日16:38:07 afes iPhone BTLEServer[107]:(注意)连接外围设备“xxx”。。。
3月18日16:38:07 afes iPhone BTLEServer[107]:(注)中央“xxx”现在已从特征“ANCS通知源”取消订阅
3月18日16:38:07 afes iPhone BTLEServer[107]:(注)中央“xxx”现在已从特色“ANCS数据源”取消订阅
3月18日16:38:08 afes iPhone BTLEServer[107]:(注意)外围设备“xxx”现在已连接
3月18日16:38:08 afes iPhone首选项[164]:(警告)CoreBluetooth:API误用:只能在连接状态下接受命令
....
3月18日16:38:09 afes iPhone BTServer[68]:与设备“xxxxxxxxx”的核心连接超时
3月18日16:38:09 afes iPhone BTLEServer[107]:(注意)外围设备“xxx”现在已断开连接:Error Domain=CBErrorDomain Code=6“连接意外超时。”UserInfo=0x1453daf0{NSLocalizedDescription=连接意外超时。}
3月18日16:38:09 afes iPhone BTLEServer[107]:(注意)连接外围设备“xxx”。。。
3月18日16:38:09 afes iPhone BTLEServer[107]:(注意)外围设备“xxx”没有使用任何内置服务,strike#1

如果我们继续正确地打开和关闭我们的金属盒,我们可以连续三次造成相同的“API误用”

导致以下消息:

Mar 18 16:38:12 afes-iPhone BTLEServer[107] <Notice>: (Note ) Peripheral "xxx" did not use any built-in service, strike #2
3月18日16:38:12 afes iPhone BTLEServer[107]:(注意)外围设备“xxx”没有使用任何内置服务,strike#2

3月18日16:38:16 afes iPhone BTLEServer[107]:(注意)外围设备“xxx”没有使用任何内置服务,strike#3

这似乎是一个“三击出局”算法,然后将外围设备放入某种“灰色列表”。时间必须在11秒左右的范围内。 我们不能放慢我们的审问速度,否则我们将面临30秒的密钥交换和配对超时

此灰色列表意味着,如果没有用户打开设置并手动连接,iOS将不再允许将此外设重新连接到ANCS

这意味着CBCentralManager -使用以下服务检索已连接的外围设备: 方法将不会检索外围设备,因为它不再连接

我们不得不添加一个变通方法,现在存储以前看到的任何外围设备的UDID,然后在回调DIDDisconnectPeripal时使用 -检索外围设备识别器:

但是,为了保持ANCS连接的连续性,我们还必须将bluetooth central UIBackground模式添加到Info.plist,以便在收到DidDisconnect外围设备和后台应用程序时重新连接。当然,如果卸载了应用程序,并且没有状态保存和恢复,ANCS连接将再次断开

为了更好地衡量,我们还利用看门狗定时器定期检查前台的连接状态

我们只能很难再现这种效果,我们的客户似乎能够经常看到它,对于不可靠的设备来说,连接的不可靠性很可能是真的

如果在iOS中更可靠地处理ANCS,我们可以使我们的应用程序更省电,开发起来也更省力

iOS 8.1和8.2上使用的设备都是iPhone4S和iPhone6


问题是:还有其他人看到过ANCS的这种行为吗?

如果你想捕获这些日志,请参阅Apple Dev Corebooth论坛上的一个帖子。另一个人看到了。我们呼吁苹果公司公布细节。我们也遇到了同样的问题。当设备处于EOR(锡罐)时,我们也会注意到这种行为。当
retrieveConnectedPeripheralsWithServices
返回未连接的外围设备时,
retrievePeripheralsWithIdentifiers
是否对您有效?WrightCS,是的。但它发现了一些与设备固件有关的其他问题。请参阅下面的评论。我们修改了外围固件,使其在尝试重新连接之前等待5秒,而不是立即尝试。第一印象很好。
Mar 18 16:38:16 afes-iPhone BTLEServer[107] <Notice>: (Note ) Peripheral "xxx" did not use any built-in service, strike #3