Posts

Post marked as solved
1 Replies
699 Views
I'm using Bonjour, NWConnection, NWBrowser, and NWListener along with the NearInteraction framework. The NearInteraction framework works best when the devices are within 9 meters - https://developer.apple.com/documentation/nearbyinteraction/initiating_and_maintaining_a_session of each other. NI works best when the peer devices are: Within nine meters of each other. Is there anyway that I can set Bonjour to not discover devices beyond or only within 9 meters?
Posted
by lance145.
Last updated
.
Post marked as solved
1 Replies
562 Views
In the delegate method below, distance is of type Float: func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject]) { 		guard let object = nearbyObjects.first else { return }           guard let distance = object.distance else { return }           print("distance is of type Float but I need to convert to meters: ", distance) } How do I convert distance into meters so that I can find out exactly how far the peers are from one another?
Posted
by lance145.
Last updated
.
Post not yet marked as solved
1 Replies
575 Views
I have the same exact problem as this question - https://developer.apple.com/forums/thread/113809. device-1 browses, discovers, and sends a message to device-2. The connection is made. I hold a copy to the outgoing connection inside an array. device-2 receives the message and I hold a copy of the incoming connection inside an array. The same thing happens in reverse with device-2 to device-1 (peer-to-peer) setup. When either device goes to the background, I iterate through the array, .cancel the connection, then remove it from the array. The problem is when the connection is no longer connected, the opposite device fires browser.browseResultsChangedHandler but it never fires connection.stateUpdateHandler, it will only fire if it itself shuts the connection down. device-1: var connections = [NWConnection]() @objc func backgroundNotification() { 		 connections.forEach({ $0.cancel() })      connections.removeAll() 		 // I've also tried cancelling and setting both the browser and listener to nil } device-1 is no longer connected, device-2 -only the browseResultsChangedHandler fires browser.browseResultsChangedHandler = { [weak self](results, changes) in 		for change in changes { 				switch change { 						// ... 						case .removed(let browseResult): 								if case .service(let name, let type, let domain, _) = browseResult.endpoint { 										// * only this runs * 								} 						default:break 				} 		} } var connections = [NWConnection]() connection.stateUpdateHandler = { [weak self](nwConnectionState) in 	// *.cancelled* and *.failed* never run   switch nwConnectionState {   // ...   case .cancelled: 			connection.cancel()   		// ... loop the array and remove the connection   case .failed(let error): 			connection.cancel()   		// ... loop the array and remove the connection   default:break   } } The odd thing is if device-2 goes to the background (same step as device-1), then connection.stateUpdateHandler does fire. Just to be clear when sending messages everything works fine on both devices and in both the browser and listener handlers.
Posted
by lance145.
Last updated
.
Post not yet marked as solved
6 Replies
5.6k Views
I'm using AVPlayer and sometimes the player randomly pauses. I'm observing \.timeControlStatus but the only response I get .paused with no info as to why it's paused. I'm also observing \.isPlaybackLikelyToKeepUp, \.isPlaybackBufferEmpty, and \.isPlaybackBufferFull but nothing fires for those. However using Notification.Name.AVPlayerItemPlaybackStalled I do get a print statement that says "stalled".  I have no idea what to do because the player is justing sitting there and I get no information as to what the problem. How can I find out the exact reason why the player is stalled? How do I resume automatic play after the player is paused? code is in attachment AVPlayer Observers and Notifications - https://developer.apple.com/forums/content/attachment/98542fe1-0678-4922-806a-e8b9ae09ceed
Posted
by lance145.
Last updated
.