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
Nearby Interaction
RSS for tagLocate and interact with nearby devices using distance, direction, and identifier.
Posts under Nearby Interaction tag
22 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have an idea for a game where the Apple TV app acts as the host and discovers nearby iOS apps that can join the game. Each iOS app needs to be able to have the user draw, tap, etc and have all the events be delivered in real time to the Apple TV where the effects will be rendered immediately (imagine a co-op game played in your lounge room where guests user their own devices to control aspects of the UI on the shared Apple TV screen)
MPC is discontinued and DeviceDiscoveryUI is limited to only a single iOS device so I’m trying to figure out the best way to do the P2P networking.
Reading/watching videos suggests that using GKMatchMaker and friends seems like it might suffer from latency problems (because everything has to go via Game Centre - or does it?) plus I’m not sure how I’d deal with the fact that the owner of the Apple TV is likely to signed into the same game centre id on both the Apple TV and their own devices to which would mean they wouldnt be able to play because the host can’t invite “themselves” on another device (or can it?)
Soooo… I’m looking for suggestions on how best to move forward. I’ve read https://developer.apple.com/documentation/technotes/tn3151-choosing-the-right-networking-api which is very useful but there’s no clear suggestion that would work.
Using the Network for the real time messaging seems doable but dealing with discovery / invites seems like a massive pain that I’d prefer to use built-in libraries if possible.
Any suggestions would be gladly received. Thanks a lot
Topic:
App & System Services
SubTopic:
Networking
Tags:
GameKit
Nearby Interaction
Multipeer Connectivity