Overview
I am running a NearbyInteaction sample.
Immediately after niSession.run(configuration!)
, func session(_ session: NISession, didInvalidateWith error: Error)
is executed. The error is as follows, but I cannot find the cause.
Error:
bluetoothPeerIdentifier: AF5ADDC1-F731-7BAD-E8C5-9230E79F8C1A Session Invalidation Error: NIERROR_ACCESSORY_PEER_DEVICE_UNAVAILABLE_DESCRIPTION Error Details:Error Domain=com.apple.NearbyInteraction Code=-5882 "NIERROR_ACCESSORY_PEER_DEVICE_UNAVAILABLE_DESCRIPTION" UserInfo={NSLocalizedRecoverySuggestion=NIERROR_ACCESSORY_PEER_DEVICE_UNAVAILABLE_RECOVERY_SUGGESTION, NSLocalizedDescription=NIERROR_ACCESSORY_PEER_DEVICE_UNAVAILABLE_DESCRIPTION, NSLocalizedFailureReason=NIERROR_ACCESSORY_PEER_DEVICE_UNAVAILABLE_FAILURE_REASON}
The sample application worked well at first. I want the application to run in the background, so I made the following changes and had problems.
Before change:
configuration = try NINearbyAccessoryConfiguration(data: configData)
After change:
configuration = try NINearbyAccessoryConfiguration( accessoryData: configData, bluetoothPeerIdentifier: peerIdentifier)
I see no problem with the application. It works fine on device A. The problem occurs on device B.
- Device A: NXP QN9090 - NXP SR150
- Device B: Nordic nRF52840 - NXP SR150
I have confirmed that the device shows up in the settings app after pairing & bonding the device.
I have confirmed that the iPhone and nRF52840 are still connected to the BLE without any problems when the error occurs.
Initialization code for NearbyInteraction:
func setupAccessory(_ configData: Data, name: String) { updateInfoLabel(with: "Received configuration data from '\(name)'. Running session.") do { guard let discoveredPeripheral = dataChannel.getDiscoveredPeripheral() else { return } let peerIdentifier = discoveredPeripheral.identifier configuration = try NINearbyAccessoryConfiguration( accessoryData: configData, bluetoothPeerIdentifier: peerIdentifier) } catch { // Stop and display the issue because the incoming data is invalid. // In your app, debug the accessory data to ensure an expected // format. updateInfoLabel( with: "Failed to create NINearbyAccessoryConfiguration for '\(name)'. Error: \(error)" ) return } // Cache the token to correlate updates with this accessory. cacheToken(configuration!.accessoryDiscoveryToken, accessoryName: name) niSession.run(configuration!) }
Environment
- Xcode 16.1
- iPhone11 (iOS 17.6.1)
- Target UWB Chip: NXP SR150
- Sample iOS Application: https://developer.apple.com/documentation/nearbyinteraction/implementing-spatial-interactions-with-third-party-accessories