我的应用程序使用corebluetooth,它扮演2个角色:
中心角色:连接到外围设备(IoT设备)以收集数据(每秒3个样本)。
外围角色:通过预定义的特性来广告和通知数据。
我的应用程序每秒从IoT获取数据3次,每次获取新数据时,它都会通过预定义的特征将数据发送出去
- (BOOL)updateValue:(NSData *)value forCharacteristic:(CBMutableCharacteristic *)characteristic onSubscribedCentrals:(nullable NSArray *)centrals;
问题是,如果有多个应用程序连接到我的应用程序以获取数据(这些应用程序使用corebluetooth并充当核心角色),则我的应用程序会非常频繁地断开与IoT设备的连接(每5-10分钟) )。
在此测试方案中,有3个应用程序连接到我的应用程序以通过通知获取数据。
测试设备为:iPad 6th gen 12.2,在连接到IoT设备时扮演中心角色,在连接到其他3个应用程序时扮演外围角色。
其他应用可在iPad 12.2,iPhone 5S iOS 11,iPad Air 12.2上运行
每一秒钟我看到了许多日志,它们向每个应用程序发送数据,为什么corebluetooth通过XPC消息使用过多的通信?
default 16:31:50.232796 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-0"
default 16:31:50.232963 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-1"
default 16:31:50.233010 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.locationd-central-57-4"
default 16:31:50.233051 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-8"
default 16:31:50.233111 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-central-55-6"
default 16:31:50.237711 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-peripheral-71-5"
default 16:31:50.237914 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-16"
default 16:31:50.238059 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.BTLEServer-peripheral-187-12"
default 16:31:50.239895 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-2"
default 16:31:50.239961 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-3"
default 16:31:50.240023 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-17"
default 16:31:50.240187 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-11"
default 16:31:50.240219 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-central-71-25"
default 16:31:50.240281 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.240313 -0600 bluetoothd Received XPC message "CBMsgIdSendValueNotification" from session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.240343 -0600 bluetoothd Sending notification to device "01030BB5-AAE1-8EEA-F758-0EBE0DD85860"
default 16:31:50.240373 -0600 bluetoothd Sending notification to device "5DC348FC-3354-19C0-5748-7F78953E556A"
default 16:31:50.240452 -0600 bluetoothd Sending notification to device "19918C2D-7AF4-78FD-8030-36DBBC614167"
default 16:31:50.240515 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-0"
default 16:31:50.240618 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-1"
default 16:31:50.240710 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.locationd-central-57-4"
default 16:31:50.240780 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-8"
default 16:31:50.240875 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-central-55-6"
default 16:31:50.240906 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-peripheral-71-5"
default 16:31:50.240936 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-16"
default 16:31:50.241065 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.BTLEServer-peripheral-187-12"
default 16:31:50.241095 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-2"
default 16:31:50.241125 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-3"
default 16:31:50.241156 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-17"
default 16:31:50.241187 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-11"
default 16:31:50.241218 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-central-71-25"
default 16:31:50.241248 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.241278 -0600 bluetoothd Received XPC message "CBMsgIdSendValueNotification" from session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.241380 -0600 bluetoothd Sending notification to device "01030BB5-AAE1-8EEA-F758-0EBE0DD85860"
default 16:31:50.241410 -0600 bluetoothd Sending notification to device "5DC348FC-3354-19C0-5748-7F78953E556A"
default 16:31:50.241471 -0600 bluetoothd Sending notification to device "19918C2D-7AF4-78FD-8030-36DBBC614167"
default 16:31:50.241531 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-0"
default 16:31:50.241561 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-1"
default 16:31:50.241624 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.locationd-central-57-4"
default 16:31:50.241654 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-8"
default 16:31:50.241683 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-central-55-6"
default 16:31:50.241714 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-peripheral-71-5"
default 16:31:50.241743 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-16"
default 16:31:50.241773 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.BTLEServer-peripheral-187-12"
default 16:31:50.242210 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-2"
default 16:31:50.242283 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-3"
default 16:31:50.242343 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-17"
default 16:31:50.242430 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-11"
default 16:31:50.242509 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-central-71-25"
default 16:31:50.242590 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.244428 -0600 bluetoothd Received XPC message "CBMsgIdSendValueNotification" from session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.244459 -0600 bluetoothd Sending notification to device "01030BB5-AAE1-8EEA-F758-0EBE0DD85860"
default 16:31:50.244488 -0600 bluetoothd Sending notification to device "5DC348FC-3354-19C0-5748-7F78953E556A"
default 16:31:50.244518 -0600 bluetoothd Sending notification to device "19918C2D-7AF4-78FD-8030-36DBBC614167"
default 16:31:50.244548 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-0"
default 16:31:50.244578 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-1"
default 16:31:50.244609 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.locationd-central-57-4"
default 16:31:50.244639 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-8"
default 16:31:50.244668 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-central-55-6"
default 16:31:50.244698 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-peripheral-71-5"
default 16:31:50.244729 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-16"
default 16:31:50.244759 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.BTLEServer-peripheral-187-12"
default 16:31:50.244788 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-2"
default 16:31:50.244818 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-3"
default 16:31:50.244848 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-17"
default 16:31:50.244879 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-11"
default 16:31:50.244909 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-central-71-25"
default 16:31:50.245185 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.245227 -0600 bluetoothd Received XPC message "CBMsgIdSendValueNotification" from session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.245258 -0600 bluetoothd Sending notification to device "01030BB5-AAE1-8EEA-F758-0EBE0DD85860"
default 16:31:50.245288 -0600 bluetoothd Sending notification to device "5DC348FC-3354-19C0-5748-7F78953E556A"
default 16:31:50.245317 -0600 bluetoothd Sending notification to device "19918C2D-7AF4-78FD-8030-36DBBC614167"
default 16:31:50.245346 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-0"
default 16:31:50.245413 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-1"
default 16:31:50.245445 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.locationd-central-57-4"
default 16:31:50.245491 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-8"
default 16:31:50.245527 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-central-55-6"
default 16:31:50.245558 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-peripheral-71-5"
default 16:31:50.245593 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-16"
default 16:31:50.245624 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.BTLEServer-peripheral-187-12"
default 16:31:50.245654 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-2"
default 16:31:50.245683 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-3"
default 16:31:50.245713 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-17"
default 16:31:50.245743 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-11"
default 16:31:50.246437 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-central-71-25"
default 16:31:50.246469 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.246500 -0600 bluetoothd Received XPC message "CBMsgIdSendValueNotification" from session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.246531 -0600 bluetoothd Sending notification to device "01030BB5-AAE1-8EEA-F758-0EBE0DD85860"
default 16:31:50.246561 -0600 bluetoothd Sending notification to device "5DC348FC-3354-19C0-5748-7F78953E556A"
default 16:31:50.246591 -0600 bluetoothd Sending notification to device "19918C2D-7AF4-78FD-8030-36DBBC614167"
default 16:31:50.246622 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-0"
default 16:31:50.246866 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-1"
default 16:31:50.246897 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.locationd-central-57-4"
default 16:31:50.246927 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-8"
default 16:31:50.246957 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-central-55-6"
default 16:31:50.246986 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-peripheral-71-5"
default 16:31:50.247016 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-16"
default 16:31:50.247047 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.BTLEServer-peripheral-187-12"
default 16:31:50.247230 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-2"
default 16:31:50.247260 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-3"
default 16:31:50.247290 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-17"
default 16:31:50.247320 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-11"
default 16:31:50.247350 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-central-71-25"
default 16:31:50.247381 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.247413 -0600 bluetoothd Received XPC message "CBMsgIdSendValueNotification" from session "com.mycompany.MyBLEApp-peripheral-230-18"
default 16:31:50.247442 -0600 bluetoothd Sending notification to device "01030BB5-AAE1-8EEA-F758-0EBE0DD85860"
default 16:31:50.247471 -0600 bluetoothd Sending notification to device "5DC348FC-3354-19C0-5748-7F78953E556A"
default 16:31:50.247500 -0600 bluetoothd Sending notification to device "19918C2D-7AF4-78FD-8030-36DBBC614167"
default 16:31:50.247530 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-0"
default 16:31:50.247567 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-1"
default 16:31:50.247598 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.locationd-central-57-4"
default 16:31:50.247629 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-8"
default 16:31:50.247659 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-central-55-6"
default 16:31:50.247689 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-peripheral-71-5"
default 16:31:50.247718 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-16"
default 16:31:50.247748 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.BTLEServer-peripheral-187-12"
default 16:31:50.247777 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-peripheral-53-2"
default 16:31:50.247806 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.wirelessproxd-central-53-3"
default 16:31:50.247869 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-central-230-17"
default 16:31:50.247929 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.sharingd-peripheral-55-11"
default 16:31:50.247989 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.apple.rapportd-central-71-25"
default 16:31:50.248524 -0600 bluetoothd Sending XPC message "CBMsgIdReadyForUpdates" to session "com.mycompany.MyBLEApp-peripheral-230-18"
每5-10分钟出现一次问题,我看到了以下消息:
default 16:31:50.984625 -0600 bluetoothd LE Link disconnected for handle 0x106a018b0 address Public A0:E6:F8:28:DF:8D with reason 708
我的应用从IoT设备的corebluetooth获得了didDisconnectedPeripheral
回调:
default 16:31:51.032169 -0600 MyBLEApp Disconnected peripheral <CBPeripheral: 0x282f64aa0, identifier = 37DE887F-674B-E861-3192-B29C7F31D3D9, name = IOTDEVICE, state = disconnected> (error: Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo={NSLocalizedDescription=The connection has timed out unexpectedly.})
为什么corebluetooth无法保持与IoT设备的连接?难道是因为我的应用程序扮演着围护角色,其他应用程序也可能与此连接吗?
如果我杀死所有其他应用程序(中心角色),此后,物联网设备将保持非常稳定的连接,并且充当外围角色的iPad只要从物联网接收数据就不会出现任何问题。 谢谢。