Hi folks We are working with our MFI External Accessory device working with our own library. We are encountering problems reestablishing EASession after disconnect/connect event of our device when the app is running in background. Our app was working great until iOS 15.7. This is happening under iOS16.1/ iOS16.2 version.
This is the behavior : the app goes into background. In that state, we disconnect our device and connect it again to the iPad and then the APP returns to foreground. When the app goes to foreground we are logging both disconnect and connect events (that's correct) but when our code reaches to
EAAccessoryManager.shared().registerForLocalNotifications() return EAAccessoryManager.shared().connectedAccessories
Although our device are connected to the iPad and the HID is shown in the iPad, EAAccessoryManager.shared().connectedAccessories function
most of the time returns empty or nil
LOG: APP > Scene changed to Foreground
2022-12-20 17:14:35 LOG: APP > Scene changed to Foreground
2022-12-20 17:14:35.700475+0100 [APP][2737:448291] -[EAAccessoryManager _applicationWillEnterForeground:]: NSConcreteNotification 0x2828eff80 {name = UIApplicationWillEnterForegroundNotification; object = <UIApplication: 0x104204b40>}
2022-12-20 17:14:35.700553+0100 [APP][2737:448610] -[EAAccessoryManager _checkForConnectedAccessories:backgroundTaskIdentifier:] inBackground 0, identifier 0
2022-12-20 17:14:35.700674+0100 [APP][2737:448610] IAPAppConnectedAccessories: __eaClientHasCheckedForConnectedAccessories 1 -> 1
2022-12-20 17:14:35.701088+0100 [APP][2737:448610] IAPAppConnectedAccessories: IAPDHasLaunched 0, IAP2DHasLaunched 0
2022-12-20 17:14:35.916878+0100 [APP][2737:448291] initialConnectedAccessories count 0
2022-12-20 17:14:35.916961+0100 [APP][2737:448291] _connectedAccessories (1)
2022-12-20 17:14:35.917000+0100 [APP][2737:448291] Done attaching initialConnectedAccessories
2022-12-20 17:14:35.917511+0100 [APP][2737:448562] Connection 1: encountered error(1:53)
2022-12-20 17:14:35.917809+0100 [APP][2737:448291] CoreAccessories accessoryInfo for departure = {
ACCExternalAccessoryPPIDKey = 509e9916a9f04f77;
ACCExternalAccessoryPrimaryUUID = "FF13BA35-002A-4F44-94EB-F090E71AAB08";
ACCExternalAccessoryProtocolDetailsKey = {
"com.irisbond.messages" = {
ACCExternalAccessoryMatchAction = 1;
ACCExternalAccessoryProtocolEndpointUUID = "FF13BA35-002A-4F44-94EB-F090E71AAB08";
ACCExternalAccessoryProtocolIndex = 0;
ACCExternalAccessoryProtocolType = 0;
ACCExternalAccessorySessionUsesSocketInterfaceKey = 1;
};
};
ACCExternalAccessoryRegionCodeKey = "<null>";
IAPAppAccessoryCapabilitiesKey = 3;
IAPAppAccessoryDockTypeKey = "";
IAPAppAccessoryFirmwareRevisionKey = "1.1.21\n";
IAPAppAccessoryFirmwareRevisionPendingKey = "<null>";
IAPAppAccessoryHardwareRevisionKey = "1.0";
IAPAppAccessoryManufacturerKey = Irisbond;
IAPAppAccessoryModelNumberKey = Hiru;
IAPAppAccessoryNameKey = Hiru;
IAPAppAccessoryPreferredAppKey = 77H2H4F7F4;
IAPAppAccessoryProtocolsKey = {
"com.irisbond.data" = 1;
"com.irisbond.messages" = 0;
"com.irisbond.updates" = 3;
"com.irisbond.video" = 2;
};
IAPAppAccessorySerialNumberKey = 1117;
IAPAppAccessoryTransportType = 8;
IAPAppAccessoryVehicleInfoInitialDataKey = {
};
IAPAppConnectionIDKey = 43587966;
}
2022-12-20 17:14:35.918708+0100 [APP][2737:448562] Connection 1: received failure notification
2022-12-20 17:14:35.918797+0100 [APP][2737:448291] -[EAAccessoryManager _externalAccessoryDisconnected:]: connectionID 43587966
2022-12-20 17:14:35 LOG: CONN > [Protocol-Updates]: disconnected from accesory Hiru
2022-12-20 17:14:35.919886+0100 [APP][2737:448562] [] nw_endpoint_flow_fillout_data_transfer_snapshot copy_info() returned NULL
2022-12-20 17:14:35.919931+0100 [APP][2737:448562] [connection] nw_connection_copy_connected_local_endpoint_block_invoke [C1] Connection has no connected path
2022-12-20 17:14:35.919962+0100 [APP][2737:448562] [connection] nw_connection_copy_connected_remote_endpoint_block_invoke [C1] Connection has no connected path
2022-12-20 17:14:35.921228+0100 [APP][2737:448291] Removing EASession F15E5A13-88CA-4D75-A288-4A63E8024DAE from list of sessionUUIDs
2022-12-20 17:14:35 LOG: CONN > [Protocol-Updates]: EA session closed.
2022-12-20 17:14:35.922326+0100 [APP][2737:448291] On: 1084 Accessory Disconnected. UUID FF13BA35-002A-4F44-94EB-F090E71AAB08 connectionID 43587966 createdByCoreAccessories 1. RegisteredForLocalNotifications Count: 5
2022-12-20 17:14:35 LOG: APP > HIRU disconnected
2022-12-20 17:14:35 LOG: CONN > [Protocol-Messages]: Connection event: 16
2022-12-20 17:14:35.927947+0100 [APP][2737:448291] On: 1050 RegisteredForLocalNotifications Count: 6
2022-12-20 17:14:35.928124+0100 [APP][2737:448291] Returning connectedAccessories count 0
2022-12-20 17:14:35 LOG: CONN >
2022-12-20 17:14:35 LOG: CONN > We didn't find devices, OUT
But in the rare case that it returns information from our connected device, we're not able to open our session again --> this is the error we receive --> 212 unable to close session for _accessory
2022-12-19 14:51:57 LOG: CONN > [Protocol-Messages]: Connection event
2022-12-19 14:51:57.052193+0100 APP[521:15745] On: 1050 RegisteredForLocalNotifications Count: 6
2022-12-19 14:51:57.052246+0100 APP[521:15745] Returning connectedAccessories count 1
2022-12-19 14:51:57 LOG: CONN > APP: Accessory identified.
2022-12-19 14:51:57 LOG: CONN > [Protocol-Messages]: Hiru Accessory identified.
2022-12-19 14:51:57.252593+0100 Calibration Hiru[521:15745] ERROR - opening session failed
2022-12-19 14:51:57.252713+0100 Calibration Hiru[521:15745] ERROR - /Library/Caches/com.apple.xbs/Sources/ExternalAccessory/EASession.m:-[EASession dealloc] - 212 unable to close session for _accessory=0x281520430 and sessionID=65536
If we perform this same test when the app is in the foreground, everything works correctly. Background disconnect/connect test was working perfectly in our app on iOS15, but not on iOS16 :(
We have found a similar thread, but we don't know if it is related to our bug
https://developer.apple.com/forums/thread/102806
looking forward to hearing from your side !
All the best