Nearby Interaction

RSS for tag

Locate and interact with nearby devices using distance, direction, and identifier.

Posts under Nearby Interaction tag

130 Posts

Post

Replies

Boosts

Views

Activity

Direction is NIL using iOS 16 BETA NearbyInteraction framework
Hi all, Recently I updated my app, which is using NearbyInteraction framework and was working great in iOS 15.x, to use new NearbyInteraction APIs introduced in iOS16. The main reason I want to test new APIs is to enable background sessions as explained in WWDC2022-10008. Actually background session is working ok with my third-party accessory, I can bring the app to the background and then back to the foreground and the Nearby Session does not get invalidated. However, I noticed that now using latest API the direction I receive is always null. I am using this API to create the session: "init(accessoryData:bluetoothPeerIdentifier:)" The ranging starts, but distance is nil in didUpdate delegate callback: "func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject])" This same code was working before, I would get the direction out of myObject.direction. I tested setting isCameraAssistanceEnabled to true, even tried adding ARSession as in WWDC just in case, but direction and estimated horizontal and vertical angles are always nil. Is there anything I am missing? Any hint how to get this fixed? Regards.
1
0
1.6k
Sep ’22
When does [NIExportedObjectForwarder didUpdateNearbyObjects] get called?
I'm testing some nearby interaction on simulators. I was able to get updates in NISession but my app crashes unexpectedly. I have checked that the session is not getting invalidated. The errors have to do with NIExportedObjectForwarder. Can anyone explain what it does or what's causing this error? 2022-06-14 17:09:23.895783-0700 Threads[23791:8863595] -[NIExportedObjectForwarder didUpdateNearbyObjects:]: unrecognized selector sent to instance 0x600002d12550 2022-06-14 17:09:23.896240-0700 Threads[23791:8863595] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NIExportedObjectForwarder didUpdateNearbyObjects:]: unrecognized selector sent to instance 0x600002d12550' *** First throw call stack: ( 0   CoreFoundation                      0x00000001072e3d70 __exceptionPreprocess + 236 1   libobjc.A.dylib                     0x0000000104ffe14c objc_exception_throw + 56 2   CoreFoundation                      0x00000001072f32f4 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0 3   CoreFoundation                      0x00000001072e7fe0 ___forwarding___ + 1440 4   CoreFoundation                      0x00000001072ea07c _CF_forwarding_prep_0 + 92 5   NearbyInteraction                   0x0000000105100c74 -[NIServerConnection _sendDistanceUpdateForRequestedPeer:forPeer:] + 1544 6   NearbyInteraction                   0x0000000105100e18 -[NIServerConnection handleDistanceUpdate:] + 312 7   NearbyInteraction                   0x0000000105101e0c __54-[NIServerConnection handleEventFromSimulatorOnQueue:]_block_invoke + 316 8   libdispatch.dylib                   0x000000010657833c _dispatch_call_block_and_release + 24 9   libdispatch.dylib                   0x0000000106579b94 _dispatch_client_callout + 16 10  libdispatch.dylib                   0x0000000106580cc4 _dispatch_lane_serial_drain + 764 11  libdispatch.dylib                   0x0000000106581978 _dispatch_lane_invoke + 436 12  libdispatch.dylib                   0x000000010658da00 _dispatch_workloop_worker_thread + 812 13  libsystem_pthread.dylib             0x00000001cc0adb40 _pthread_wqthread + 284 14  libsystem_pthread.dylib             0x00000001cc0ac904 start_wqthread + 8 ) libc++abi: terminating with uncaught exception of type NSException
1
0
1k
Jun ’22
Why is there a limit on the number of nearby objects of a single session
Hi, The documentation for NISession says: One session represents an interaction between the user and a single nearby object. To interact with multiple nearby objects, create a separate session for each. However, NISessionDelegate method session (NISession,  didUpdate : [NINearbyObject]) take multiple nearby objects as a parameter. I find these two contradicting each other. Is it even possible to add multiple peers for a single session? If so, what's the best practice to do that? JK
0
0
1.3k
Jun ’22
Multicast on third-party devices
Hello, I wonder if multicast is possible on the third-party device side. If I understand correctly, all devices in a multicast session have the same session ID. As the iPhone decides this parameter, I will never be able to use this feature on my third-party device. Am I correct ? Is it possible to connect more than 5 iPhone to a third-party UWB device ? Thanks for reading me!
1
0
1.5k
Jun ’22
Nearby Interaction GATT Service
Hello, We are a company working on Ultra Wideband solutions and, hence, using Apple's NearbyInteraction framework to establish UWB Ranging sessions with our UWB-enabled third-party accessory. This week we were excited about the new background UWB Ranging session possibility, which opens new use cases. The wwdc2022 10008 video that provides the technical details for this feature indicates that the third-party accessory is responsible to expose the Nearby Interaction GATT Server. We don't manage to get full details about what needs to be implemented to by compliant with Apple's framework. The URL below indicates that full BLE details should be explained in the "Nearby Interaction Accessory Protocol Specification" but we don't see any info there. https://developer.apple.com/documentation/nearbyinteraction/ninearbyaccessoryconfiguration https://developer.apple.com/nearby-interaction/specification/ Can someone indicate us where the find full details for this background Nearby Interaction feature? Thanks in advance. Regards.
1
0
2.1k
Jun ’22
U1/UWB distance
Hello, I recently experimented with the Nearby Interactions demo project for the U1/UWB chip. When using my iPhone 12 Pro and an Apple Watch Series 6 I was only able to go a distance of 16 feet before to connection would seem to break. Does anyone know if there is a way to utilize these chips to support calculating the distance between devices at a greater distance than what I was able to get?
1
0
3.4k
May ’22
NEARBY INTERACTION
Will the apple have the plan to support or interact with other UWB DEVICES ? for example iphone 11 can measure the distance between iphone 11 and other brand of UWB devices or third-party UWB devices , BECAUSE IF APPLE HAS the SUPPORT OF THE API FOR U1 chip OR IPHONE 11 TO INTERACT OR MEASURE THE DISTANCE WITH OTHER BRAND OF UWB DEVICES THAN ONLY IPHONE11 OR APPLE AIRTAG , I REALLY THINK THE APPLE DEVELOPERs WILL BE ABLE TO CREATE MANY OF CREATIVE APPs more and more ,when the apple allow the iphone 11 interact with other brand UWB THAN ONLY iphone 11 or apple airtag or only apple products I meant i just want to measure the distance between iphone 11 and the UWB anchor ( UWB arduino device ) or other brand of UWB anchor or many of various UWB- IoT devices I AM ONE OF APP DEVELOPERS , I PERSONALLY ASK THE APPLE TO CREATE THE UWB API THAT ALLOW THE IPHONE 11 INTERACT OR MEASURE THE DISTANCE BETWEEN IPHONE 11 AND OTHER BRAND OF UWB DEVICES OR ANCHOR AS ARDUINO so will the apple have the plan to support or interact with other UWB DEVICES soon ? when ?
4
0
2.9k
May ’22
Combine multiple outgoing NISessions with multiple NINearbyPeerConfiguration objects when data is received using Bonjour
Because of the 8 peer limit I'm using NWListener, NWBrowser, NWConnection, and Bonjour for up to 20 peer-to-peer concurrent connections. I followed this answer - https://developer.apple.com/forums/thread/652180 and this answer - https://developer.apple.com/forums/thread/661148 which are both from Apple engineers. The first one said to create multiple concurrent NISessions: All NISessions are peer-to-peer and as a result, creating multiple NISession objects is necessary to have multiple concurrent sessions. One approach is to create a dictionary between an identifier for the peer (i.e. a user identifier provided by your app MyAppUserID) and the NISession objects while also keeping track of the NIDiscoveryToken for each peer identifier:  var sessions = [MyAppUserID: NISession]() var peerTokensMapping = [NIDiscoveryToken: MyAppUserID]() And the second answer said to perform interactions with multiple iPhones: Create an NISession for each peer you would like to interact with. For example, if you are interacting with two peers, create 2 * NISession objects. Each NISession will have a unique NIDiscoveryToken associated with it. Share discovery token #1 with peer #1, and share discovery token #2 with peer #2. When you receive discovery tokens from peers #1 and #2, create 2 * NINearbyPeerConfiguration objects and use them to run sessions #1 and #2, respectively. The problem is when sending out a NIDiscoveryToken via NWConnection, I can't find a way to link to the NISession from the sent out data to the token that is received from the incoming data after I initialize a NINearbyPeerConfiguration object: eg. User object which is sent and received when other devices are discovered class User: NSObject, NSSecureCoding { 		var uid: String? 		var peerToken: NIDiscoveryToken? = nil 		init(uid: String, peerToken: NIDiscoveryToken) {...} 		// ... encoder for uid and peerToken 		// ... decoder for uid and peerToken } Send current user's NIDiscoveryToken data via NWBrowser and NWConnection and save it to the peerTokensMapping dictionary and save the session to the sessionsArr let currentUserId = "qwerty" var sessionsArr = [NISession]() var sessions = [String: NISession]() var peerTokensMapping = [NIDiscoveryToken: String]() func sendDataWhenNewDeviceIsDiscovered() { 		let session = NISession() 		session.delegate = self 		guard let myToken = session.discoveryToken else { return } 		let user = User(uid: currentUserId, peerToken: myToken) 		guard let outgoingData = try? NSKeyedArchiver.archivedData(withRootObject: user, 																														 requiringSecureCoding: true) 		else { return } 		let message = NWProtocolWebSocket.Metadata(opcode: .text) 		let context = NWConnection.ContentContext(identifier: "send", metadata: [message]) 		connection.send(content: outgoingData, contentContext: context, isComplete: true, completion: .contentProcessed({ [weak self](error) in             		if let error = error { return } 				self?.sessionsArr.append(session) 				self?.peerTokensMapping[myToken] = self!.currentUserId     		print("Successfully Sent") 		})) } Receive other user's NIDiscoveryToken data via NWListener and NWConnection. connection.receive(minimumIncompleteLength: 1, maximumLength: 65535) { 		[weak self](data, context, isComplete, error) in 		if let err = error { return } 		if let data = data, !data.isEmpty { 				self?.decodeReceived(data) 		} } func decodeReceived(_ data: Data) { 		guard let incomingData = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? User 		else { return } 		guard let uid = incomingData.uid, let peerToken = incomingData.peerToken 		else { return } 		let config = NINearbyPeerConfiguration(peerToken: peerToken) 		/* not sure what to do here to get the session that was created when the data was sent out */ 		for (key,_) in peerTokensMapping { 				if key.??? == peerToken.??? { 						session.run(config) 						self.sessions[currentUserId] = session 						break 				} 		} 		/* or try this but this is the other user's peerToken so this will never work */ 		for session in self.sessionsArr { 				if session.discoveryToken ?? "" == peerToken { 						session.run(config) 						self.sessions[currentUserId] = session 						break 				} 		} } Once the NINearbyPeerConfiguration is initialized how do I connect the incoming peerToken with the correct one that was sent out above that is currently inside the peerTokensMapping dict or the sessionsArr so that I can get the session and call session.run(config)
1
0
1.9k
Apr ’22
Nearby Interaction
Hello All, I am facing one problem in the Nearby Interaction library, I want to connect multiple devices at the same time, Right now NISession is disconnect itself when a new device comes in range and connect with a new device My question is how can I connect with multiple devices at the same time and access the distance of all the connected devices. This how i am using right now final class NearbyInteractionManager: NSObject {   static let instance = NearbyInteractionManager()   var sessionNI: NISession?   weak var delegate: NearbyInteractionManagerDelegate?       func start() {     sessionNI = NISession()     sessionNI?.delegate = self     MultipeerConnectivityManager.instance.delegate = self     MultipeerConnectivityManager.instance.startBrowsingForPeers()   }         private var discoveryTokenData: Data {     guard let token = sessionNI?.discoveryToken,        let data = try? NSKeyedArchiver.archivedData(withRootObject: token, requiringSecureCoding: true) else {       fatalError("can't convert token to data")     }     return data   } } extension NearbyInteractionManager: MultipeerConnectivityManagerDelegate {   func connectedDevicesChanged(devices: [String]) {     print("connected devices changed \(devices)")   }       func connectedToDevice() {     print("connected to device")     MultipeerConnectivityManager.instance.shareDiscoveryToken(data: discoveryTokenData)   }       func receivedDiscoveryToken(data: Data) {     print("data received")     guard let token = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NIDiscoveryToken.self, from: data) else {       fatalError("Unexpectedly failed to encode discovery token.")     }     let configuration = NINearbyPeerConfiguration(peerToken: token)     sessionNI?.run(configuration)   } } // MARK: - NISessionDelegate extension NearbyInteractionManager: NISessionDelegate {           func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject]) {     delegate?.didUpdateNearbyObjects(objects: nearbyObjects, token: nearbyObjects[0].discoveryToken)   }       func session(_ session: NISession, didRemove nearbyObjects: [NINearbyObject], reason: NINearbyObject.RemovalReason) {}   func sessionWasSuspended(_ session: NISession) {}   func sessionSuspensionEnded(_ session: NISession) {}   func session(_ session: NISession, didInvalidateWith error: Error) {} } protocol NearbyInteractionManagerDelegate: class {   func didUpdateNearbyObjects(objects: [NINearbyObject], token: NIDiscoveryToken) } Any update will be very helpful full Thank you
0
0
1.1k
Mar ’22
Can we broadcast light custom application data using ultra U1 technology without BT/Internet connectivity?
Can we broadcast light custom application data using ultra U1 technology without BT/Internet connectivity? I have UWB Ultra wideband integrated in my multiple iPhones using which I want to send/receive custom data (very low amount, possibly couple of integers with interval) between two iPhones without requiring any validation (connection establishment). The requirement is similar to broadcasting advertisement message of BT/WiFi. I wonder for UWB if it is possible or not. Any paper or article if feasible?
0
0
1.1k
Jan ’22
Does U1 in Iphone utilize AoA?
Hello, i want to know if an Iphone 11 with its U1 Chip for example is able to get angle information of another Iphone and in how many dimensions. I reckon more than 2D is not possible. An Iphone in combination with the Airtag seems to be able to get angular information but the antenna array might be provided in the tag rather than the Iphone. Thanks for your help!
0
0
1.2k
Dec ’21
What happened with User Nearby Interaction framework on IOS 15?
I installed an official app made by the apple from there https://developer.apple.com/documentation/nearbyinteraction/implementing_interactions_between_users_in_close_proximity on my IOS 15 iPhone 11 and it doesn't work. Every time when NISession try to run it turns to suspended mod with no reasons. Does anyone have idea?
1
0
1.3k
Dec ’21
Direction is NIL using iOS 16 BETA NearbyInteraction framework
Hi all, Recently I updated my app, which is using NearbyInteraction framework and was working great in iOS 15.x, to use new NearbyInteraction APIs introduced in iOS16. The main reason I want to test new APIs is to enable background sessions as explained in WWDC2022-10008. Actually background session is working ok with my third-party accessory, I can bring the app to the background and then back to the foreground and the Nearby Session does not get invalidated. However, I noticed that now using latest API the direction I receive is always null. I am using this API to create the session: "init(accessoryData:bluetoothPeerIdentifier:)" The ranging starts, but distance is nil in didUpdate delegate callback: "func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject])" This same code was working before, I would get the direction out of myObject.direction. I tested setting isCameraAssistanceEnabled to true, even tried adding ARSession as in WWDC just in case, but direction and estimated horizontal and vertical angles are always nil. Is there anything I am missing? Any hint how to get this fixed? Regards.
Replies
1
Boosts
0
Views
1.6k
Activity
Sep ’22
session(_:didRemove:reason:) called with wrong reason
The document says session(_:didRemove:reason:) is called when a peer has ended his session by calling its invalidate(). I expect the removal reason to be .peerEnded but I get .timeout.
Replies
1
Boosts
0
Views
924
Activity
Jul ’22
When does [NIExportedObjectForwarder didUpdateNearbyObjects] get called?
I'm testing some nearby interaction on simulators. I was able to get updates in NISession but my app crashes unexpectedly. I have checked that the session is not getting invalidated. The errors have to do with NIExportedObjectForwarder. Can anyone explain what it does or what's causing this error? 2022-06-14 17:09:23.895783-0700 Threads[23791:8863595] -[NIExportedObjectForwarder didUpdateNearbyObjects:]: unrecognized selector sent to instance 0x600002d12550 2022-06-14 17:09:23.896240-0700 Threads[23791:8863595] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NIExportedObjectForwarder didUpdateNearbyObjects:]: unrecognized selector sent to instance 0x600002d12550' *** First throw call stack: ( 0   CoreFoundation                      0x00000001072e3d70 __exceptionPreprocess + 236 1   libobjc.A.dylib                     0x0000000104ffe14c objc_exception_throw + 56 2   CoreFoundation                      0x00000001072f32f4 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0 3   CoreFoundation                      0x00000001072e7fe0 ___forwarding___ + 1440 4   CoreFoundation                      0x00000001072ea07c _CF_forwarding_prep_0 + 92 5   NearbyInteraction                   0x0000000105100c74 -[NIServerConnection _sendDistanceUpdateForRequestedPeer:forPeer:] + 1544 6   NearbyInteraction                   0x0000000105100e18 -[NIServerConnection handleDistanceUpdate:] + 312 7   NearbyInteraction                   0x0000000105101e0c __54-[NIServerConnection handleEventFromSimulatorOnQueue:]_block_invoke + 316 8   libdispatch.dylib                   0x000000010657833c _dispatch_call_block_and_release + 24 9   libdispatch.dylib                   0x0000000106579b94 _dispatch_client_callout + 16 10  libdispatch.dylib                   0x0000000106580cc4 _dispatch_lane_serial_drain + 764 11  libdispatch.dylib                   0x0000000106581978 _dispatch_lane_invoke + 436 12  libdispatch.dylib                   0x000000010658da00 _dispatch_workloop_worker_thread + 812 13  libsystem_pthread.dylib             0x00000001cc0adb40 _pthread_wqthread + 284 14  libsystem_pthread.dylib             0x00000001cc0ac904 start_wqthread + 8 ) libc++abi: terminating with uncaught exception of type NSException
Replies
1
Boosts
0
Views
1k
Activity
Jun ’22
Why is there a limit on the number of nearby objects of a single session
Hi, The documentation for NISession says: One session represents an interaction between the user and a single nearby object. To interact with multiple nearby objects, create a separate session for each. However, NISessionDelegate method session (NISession,  didUpdate : [NINearbyObject]) take multiple nearby objects as a parameter. I find these two contradicting each other. Is it even possible to add multiple peers for a single session? If so, what's the best practice to do that? JK
Replies
0
Boosts
0
Views
1.3k
Activity
Jun ’22
Multicast on third-party devices
Hello, I wonder if multicast is possible on the third-party device side. If I understand correctly, all devices in a multicast session have the same session ID. As the iPhone decides this parameter, I will never be able to use this feature on my third-party device. Am I correct ? Is it possible to connect more than 5 iPhone to a third-party UWB device ? Thanks for reading me!
Replies
1
Boosts
0
Views
1.5k
Activity
Jun ’22
Nearby Interaction GATT Service
Hello, We are a company working on Ultra Wideband solutions and, hence, using Apple's NearbyInteraction framework to establish UWB Ranging sessions with our UWB-enabled third-party accessory. This week we were excited about the new background UWB Ranging session possibility, which opens new use cases. The wwdc2022 10008 video that provides the technical details for this feature indicates that the third-party accessory is responsible to expose the Nearby Interaction GATT Server. We don't manage to get full details about what needs to be implemented to by compliant with Apple's framework. The URL below indicates that full BLE details should be explained in the "Nearby Interaction Accessory Protocol Specification" but we don't see any info there. https://developer.apple.com/documentation/nearbyinteraction/ninearbyaccessoryconfiguration https://developer.apple.com/nearby-interaction/specification/ Can someone indicate us where the find full details for this background Nearby Interaction feature? Thanks in advance. Regards.
Replies
1
Boosts
0
Views
2.1k
Activity
Jun ’22
Can I create hands-free applications using the nearby interaction framework?
I want to create a hands-free application (e.g. smart lock)using the Nearby Interaction framework. Nearby Interaction sessions can only be active when the app is in the foreground, however, it can't be a complete hands-free application. Does anyone have any good ideas?
Replies
2
Boosts
0
Views
1.5k
Activity
May ’22
Can we use airbags with nearby interactions api
Does Nearby Interaction API support interaction between an iPhone with U1 chip with AirTags?
Replies
3
Boosts
0
Views
2.4k
Activity
May ’22
U1/UWB distance
Hello, I recently experimented with the Nearby Interactions demo project for the U1/UWB chip. When using my iPhone 12 Pro and an Apple Watch Series 6 I was only able to go a distance of 16 feet before to connection would seem to break. Does anyone know if there is a way to utilize these chips to support calculating the distance between devices at a greater distance than what I was able to get?
Replies
1
Boosts
0
Views
3.4k
Activity
May ’22
NEARBY INTERACTION
Will the apple have the plan to support or interact with other UWB DEVICES ? for example iphone 11 can measure the distance between iphone 11 and other brand of UWB devices or third-party UWB devices , BECAUSE IF APPLE HAS the SUPPORT OF THE API FOR U1 chip OR IPHONE 11 TO INTERACT OR MEASURE THE DISTANCE WITH OTHER BRAND OF UWB DEVICES THAN ONLY IPHONE11 OR APPLE AIRTAG , I REALLY THINK THE APPLE DEVELOPERs WILL BE ABLE TO CREATE MANY OF CREATIVE APPs more and more ,when the apple allow the iphone 11 interact with other brand UWB THAN ONLY iphone 11 or apple airtag or only apple products I meant i just want to measure the distance between iphone 11 and the UWB anchor ( UWB arduino device ) or other brand of UWB anchor or many of various UWB- IoT devices I AM ONE OF APP DEVELOPERS , I PERSONALLY ASK THE APPLE TO CREATE THE UWB API THAT ALLOW THE IPHONE 11 INTERACT OR MEASURE THE DISTANCE BETWEEN IPHONE 11 AND OTHER BRAND OF UWB DEVICES OR ANCHOR AS ARDUINO so will the apple have the plan to support or interact with other UWB DEVICES soon ? when ?
Replies
4
Boosts
0
Views
2.9k
Activity
May ’22
which chip is recommended by Apple for 3rd party "Airtags+"
Which UWB chip is recommended by Apple to be used, if one wants to build an interactive Airtags device? Is there a support for 3rd party tag vendors at all?
Replies
1
Boosts
0
Views
1.8k
Activity
May ’22
Combine multiple outgoing NISessions with multiple NINearbyPeerConfiguration objects when data is received using Bonjour
Because of the 8 peer limit I'm using NWListener, NWBrowser, NWConnection, and Bonjour for up to 20 peer-to-peer concurrent connections. I followed this answer - https://developer.apple.com/forums/thread/652180 and this answer - https://developer.apple.com/forums/thread/661148 which are both from Apple engineers. The first one said to create multiple concurrent NISessions: All NISessions are peer-to-peer and as a result, creating multiple NISession objects is necessary to have multiple concurrent sessions. One approach is to create a dictionary between an identifier for the peer (i.e. a user identifier provided by your app MyAppUserID) and the NISession objects while also keeping track of the NIDiscoveryToken for each peer identifier:  var sessions = [MyAppUserID: NISession]() var peerTokensMapping = [NIDiscoveryToken: MyAppUserID]() And the second answer said to perform interactions with multiple iPhones: Create an NISession for each peer you would like to interact with. For example, if you are interacting with two peers, create 2 * NISession objects. Each NISession will have a unique NIDiscoveryToken associated with it. Share discovery token #1 with peer #1, and share discovery token #2 with peer #2. When you receive discovery tokens from peers #1 and #2, create 2 * NINearbyPeerConfiguration objects and use them to run sessions #1 and #2, respectively. The problem is when sending out a NIDiscoveryToken via NWConnection, I can't find a way to link to the NISession from the sent out data to the token that is received from the incoming data after I initialize a NINearbyPeerConfiguration object: eg. User object which is sent and received when other devices are discovered class User: NSObject, NSSecureCoding { 		var uid: String? 		var peerToken: NIDiscoveryToken? = nil 		init(uid: String, peerToken: NIDiscoveryToken) {...} 		// ... encoder for uid and peerToken 		// ... decoder for uid and peerToken } Send current user's NIDiscoveryToken data via NWBrowser and NWConnection and save it to the peerTokensMapping dictionary and save the session to the sessionsArr let currentUserId = "qwerty" var sessionsArr = [NISession]() var sessions = [String: NISession]() var peerTokensMapping = [NIDiscoveryToken: String]() func sendDataWhenNewDeviceIsDiscovered() { 		let session = NISession() 		session.delegate = self 		guard let myToken = session.discoveryToken else { return } 		let user = User(uid: currentUserId, peerToken: myToken) 		guard let outgoingData = try? NSKeyedArchiver.archivedData(withRootObject: user, 																														 requiringSecureCoding: true) 		else { return } 		let message = NWProtocolWebSocket.Metadata(opcode: .text) 		let context = NWConnection.ContentContext(identifier: "send", metadata: [message]) 		connection.send(content: outgoingData, contentContext: context, isComplete: true, completion: .contentProcessed({ [weak self](error) in             		if let error = error { return } 				self?.sessionsArr.append(session) 				self?.peerTokensMapping[myToken] = self!.currentUserId     		print("Successfully Sent") 		})) } Receive other user's NIDiscoveryToken data via NWListener and NWConnection. connection.receive(minimumIncompleteLength: 1, maximumLength: 65535) { 		[weak self](data, context, isComplete, error) in 		if let err = error { return } 		if let data = data, !data.isEmpty { 				self?.decodeReceived(data) 		} } func decodeReceived(_ data: Data) { 		guard let incomingData = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? User 		else { return } 		guard let uid = incomingData.uid, let peerToken = incomingData.peerToken 		else { return } 		let config = NINearbyPeerConfiguration(peerToken: peerToken) 		/* not sure what to do here to get the session that was created when the data was sent out */ 		for (key,_) in peerTokensMapping { 				if key.??? == peerToken.??? { 						session.run(config) 						self.sessions[currentUserId] = session 						break 				} 		} 		/* or try this but this is the other user's peerToken so this will never work */ 		for session in self.sessionsArr { 				if session.discoveryToken ?? "" == peerToken { 						session.run(config) 						self.sessions[currentUserId] = session 						break 				} 		} } Once the NINearbyPeerConfiguration is initialized how do I connect the incoming peerToken with the correct one that was sent out above that is currently inside the peerTokensMapping dict or the sessionsArr so that I can get the session and call session.run(config)
Replies
1
Boosts
0
Views
1.9k
Activity
Apr ’22
Cant use Nearby Interactions Framework on Xcode 13
Hi there, Im trying to use the Nearby Interactions, but when i do the import, XCode tells me that "File 'HomeViewController.swift' is part of module 'NearbyInteraction'; ignoring import" and when i want to create a NISession object it says that cant find NISession in this scope Any fix for this? Thank you
Replies
0
Boosts
0
Views
907
Activity
Mar ’22
Nearby Interaction
Hello All, I am facing one problem in the Nearby Interaction library, I want to connect multiple devices at the same time, Right now NISession is disconnect itself when a new device comes in range and connect with a new device My question is how can I connect with multiple devices at the same time and access the distance of all the connected devices. This how i am using right now final class NearbyInteractionManager: NSObject {   static let instance = NearbyInteractionManager()   var sessionNI: NISession?   weak var delegate: NearbyInteractionManagerDelegate?       func start() {     sessionNI = NISession()     sessionNI?.delegate = self     MultipeerConnectivityManager.instance.delegate = self     MultipeerConnectivityManager.instance.startBrowsingForPeers()   }         private var discoveryTokenData: Data {     guard let token = sessionNI?.discoveryToken,        let data = try? NSKeyedArchiver.archivedData(withRootObject: token, requiringSecureCoding: true) else {       fatalError("can't convert token to data")     }     return data   } } extension NearbyInteractionManager: MultipeerConnectivityManagerDelegate {   func connectedDevicesChanged(devices: [String]) {     print("connected devices changed \(devices)")   }       func connectedToDevice() {     print("connected to device")     MultipeerConnectivityManager.instance.shareDiscoveryToken(data: discoveryTokenData)   }       func receivedDiscoveryToken(data: Data) {     print("data received")     guard let token = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NIDiscoveryToken.self, from: data) else {       fatalError("Unexpectedly failed to encode discovery token.")     }     let configuration = NINearbyPeerConfiguration(peerToken: token)     sessionNI?.run(configuration)   } } // MARK: - NISessionDelegate extension NearbyInteractionManager: NISessionDelegate {           func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject]) {     delegate?.didUpdateNearbyObjects(objects: nearbyObjects, token: nearbyObjects[0].discoveryToken)   }       func session(_ session: NISession, didRemove nearbyObjects: [NINearbyObject], reason: NINearbyObject.RemovalReason) {}   func sessionWasSuspended(_ session: NISession) {}   func sessionSuspensionEnded(_ session: NISession) {}   func session(_ session: NISession, didInvalidateWith error: Error) {} } protocol NearbyInteractionManagerDelegate: class {   func didUpdateNearbyObjects(objects: [NINearbyObject], token: NIDiscoveryToken) } Any update will be very helpful full Thank you
Replies
0
Boosts
0
Views
1.1k
Activity
Mar ’22
NISessionDelegate: didInvalidateWith error
Hi, My sample work fine with 2 sessions on simulators, but don't work between 2 devices (iPhone 11 Pro and iPhone 13 Pro), or one device and one simulator. (iOS 14) I get didInvalidateWith Error (Domain=com.apple.NearbyInteraction Code=-5884). I re-tried with new session on error, but don't work. Any suggestion? Thanks
Replies
0
Boosts
0
Views
926
Activity
Feb ’22
Can we broadcast light custom application data using ultra U1 technology without BT/Internet connectivity?
Can we broadcast light custom application data using ultra U1 technology without BT/Internet connectivity? I have UWB Ultra wideband integrated in my multiple iPhones using which I want to send/receive custom data (very low amount, possibly couple of integers with interval) between two iPhones without requiring any validation (connection establishment). The requirement is similar to broadcasting advertisement message of BT/WiFi. I wonder for UWB if it is possible or not. Any paper or article if feasible?
Replies
0
Boosts
0
Views
1.1k
Activity
Jan ’22
what kind of UWB applications have you tried/implemented?
I would like to hear from you.
Replies
0
Boosts
0
Views
1.3k
Activity
Jan ’22
Can the U1 chip and UWB be used to locate and share files from one iPhone to another
I am creating an IOS app using swift and was wondering if the Nearby Interaction framework (https://developer.apple.com/documentation/nearbyinteraction) could be used to locate and transfer files from one iPhone to another.
Replies
0
Boosts
0
Views
967
Activity
Jan ’22
Does U1 in Iphone utilize AoA?
Hello, i want to know if an Iphone 11 with its U1 Chip for example is able to get angle information of another Iphone and in how many dimensions. I reckon more than 2D is not possible. An Iphone in combination with the Airtag seems to be able to get angular information but the antenna array might be provided in the tag rather than the Iphone. Thanks for your help!
Replies
0
Boosts
0
Views
1.2k
Activity
Dec ’21
What happened with User Nearby Interaction framework on IOS 15?
I installed an official app made by the apple from there https://developer.apple.com/documentation/nearbyinteraction/implementing_interactions_between_users_in_close_proximity on my IOS 15 iPhone 11 and it doesn't work. Every time when NISession try to run it turns to suspended mod with no reasons. Does anyone have idea?
Replies
1
Boosts
0
Views
1.3k
Activity
Dec ’21