Post

Replies

Boosts

Views

Activity

Problems setting up server using Network.framework
I’m pulling out my hair trying to reverse-engineer the more-or-less undocumented Network framework. It appears that two things are happening, one is that the listener is accepting two connection requests, one on ipv4 and one on ipv6. Secondly, it seems that the the connection immediately sets isComplete. Also, what does prohibit joining mean in the connection? server: did accept connection: [C1 ::1.63423 tcp, local: ::1.63406, server, prohibit joining, path satisfied (Path is satisfied), interface: lo0] It sure would be nice to have more examples of this framework in action, it feels like Apple is not really committed to it and that worries me. class Server { 		var publisher = PassthroughSubject<Data, NWError>() 		 		private var connection: NWConnection? = nil 		let listener: NWListener 		 		init() { 				listener = try! NWListener(using: .tcp) 		} 		 		func report(_ msg: String) { 				print("server: \(msg)") 		} 		 		func start() throws { 				report("start server") 				 				listener.service = NWListener.Service(name: bonjourName, type: bonjourService, domain: nil) 				listener.stateUpdateHandler = self.stateDidChange(to:) 				listener.newConnectionHandler = self.didAccept(nwConnection:) 				listener.serviceRegistrationUpdateHandler = self.serviceRegistrationUpdateHandler 				listener.start(queue: .main) 		} 		 		private func stateDidChange(to newState: NWListener.State) { 				switch newState { 				case .ready: 						report("Server ready service=\(listener.service) port=\(listener.port)") 				case .failed(let error): 						report("Server failure, error: \(error.localizedDescription)") 						publisher.send(completion: Subscribers.Completion.failure(error)) 				default: 						break 				} 		} 		 		private func serviceRegistrationUpdateHandler(_ change: NWListener.ServiceRegistrationChange) { 				report("registration did change: \(change)") 		} 		 		private func didAccept(nwConnection: NWConnection) { 				report("did accept connection: \(nwConnection)") 				connection = nwConnection 				connection?.stateUpdateHandler = self.stateDidChange 				connection?.start(queue: .main) 				receive() 		} 		private func stateDidChange(to state: NWConnection.State) { 				switch state { 				case .waiting(let error): 						publisher.send(completion: Subscribers.Completion.failure(error)) 				case .ready: 						report("connection ready") 				case .failed(let error): 						publisher.send(completion: Subscribers.Completion.failure(error)) 						connectionDidFail(error: error) 				default: 						break 				} 		} 		 		// functions removed to make space 		 		private func receive() { 				connection?.receive(minimumIncompleteLength: 1, maximumLength: Int.max) { (data, _, isComplete, error) in 						if let error = error { 								self.report("connection failed: \(error)") 								self.connectionDidFail(error: error) 								return 						} 						 						if let data = data, !data.isEmpty { 								self.report("connection did receive, data: \(data)") 								self.publisher.send(data) 						} 						if isComplete { 								self.report("is complete") //								self.connectionDidEnd() 								return 						} else { 								self.report("setup next read") 								self.receive() 						} 				} 		} 	 		func send(data: Data) { 				report("connection will send data: \(data)") 				self.connection?.send(content: data, contentContext: .defaultStream, completion: .contentProcessed( { error in 						if let error = error { 								self.connectionDidFail(error: error) 								return 						} 						self.report("connection did send, data: \(data)") 				})) 		} 		 		func sendStreamOriented(connection: NWConnection, data: Data) { 				connection.send(content: data, completion: .contentProcessed({ error in 						if let error = error { 								self.connectionDidFail(error: error) 						} 				})) 		} }
7
0
2.4k
Jul ’20
Getting four accepts for a single incoming connection request
Hi, I've constructed a NWListener closely based on the example provided here: https://developer.apple.com/forums/thread/653925?login=true&page=1#621284022 The problem is that the example specifically only handles a single connection request and then ignores all others. I've removed that logic. The problem is that for code running on two simulators (tvOS and iOS) I get four accepts each time I connect from the client. They are coming in pairs of ipv4/ipv6. The second address might be the simulator,.0.5 is the mac. I need to implement a server that accepts as many connections over time as needed. My questions are a) can I only listen on one protocol, for example ipv6 only? b) if not how should I ignore the other connection? I don't seem to get information into newConnectionHandler, which is too late. c) why am I getting a second pair of connections? Thanks in advance for your help! Cliff func startListener() { 				do { 						let tcpOption = NWProtocolTCP.Options() 						tcpOption.enableKeepalive = true 						tcpOption.keepaliveIdle = 2 						 						let params = NWParameters(tls: nil, tcp: tcpOption) 						params.includePeerToPeer = true 						 						let listener = try NWListener(using: params) 						networkListener = listener 						listener.service = NWListener.Service(name: NetworkConstants.serviceName, type: NetworkConstants.serviceType) 						listener.newConnectionLimit = NWListener.InfiniteConnectionLimit 						 						listener.stateUpdateHandler = { [weak self] newState in 								guard let strongSelf = self else { return } 								switch newState { 								case .ready: 										let listenerMessage = "listening on \(NetworkConstants.serviceName) \(NetworkConstants.serviceType) \(String(describing: strongSelf.networkListener!.port))" 										strongSelf.networkDelegate?.didReceiveListenerUpdate(listener: strongSelf, didUpdateMessage: listenerMessage) 								case .failed(let error): 										strongSelf.networkListener?.cancel() 										if strongSelf.didListenerFail { 												print("listener did fail") 												strongSelf.didListenerFail = true 												NetworkListener.shared.startListener() 										} else { 												let errorMessage = "Listener - failed with \(error.localizedDescription), restarting" 												strongSelf.networkDelegate?.didReceiveListenerUpdate(listener: strongSelf, didUpdateMessage: errorMessage) 										} 								default: 										print("listener: unhandled state \(newState)") 										break 								} 						} 						 						listener.newConnectionHandler = { [weak self] newConnection in 								guard let strongSelf = self else { return } 								strongSelf.networkDelegate?.didReceiveListenerUpdate(listener: strongSelf, didUpdateMessage: "Listener received a new connection") 								strongSelf.networkDelegate?.didReceiveNewConnection(listener: strongSelf, newConnection: newConnection) 						} 						 						listener.start(queue: .main) 				} catch { 						print("Can't make listener: \(error.localizedDescription)") 				} 		} listener: ScreenshotServer.NetworkListener: Listener received a new connection listener: ScreenshotServer.NetworkListener: new connection [C1 ::1.52396 tcp, local: ::1.52309, server, prohibit joining, path satisfied (Path is satisfied), interface: lo0] listener: ScreenshotServer.NetworkListener: Listener received a new connection listener: ScreenshotServer.NetworkListener: new connection [C2 192.168.0.5:52397 tcp, local: 192.168.0.5:52309, server, prohibit joining, path satisfied (Path is satisfied), interface: lo0] listener: ScreenshotServer.NetworkListener: Listener received a new connection listener: ScreenshotServer.NetworkListener: new connection [C3 192.168.0.2:52398 tcp, local: 192.168.0.2:52309, server, prohibit joining, path satisfied (Path is satisfied), interface: lo0] listener: ScreenshotServer.NetworkListener: Listener received a new connection listener: ScreenshotServer.NetworkListener: new connection [C4 169.254.240.25:52399 tcp, local: 169.254.240.25:52309, server, prohibit joining, path satisfied (Path is satisfied), interface: lo0]
4
1
1.2k
Jul ’20
Disable scrolling in SwiftUI List?
Hi, is it possible to disable scrolling behavior in the SwiftUI List view? I'd like to take advantage of the new grouping features List(content, children: \.children)  in List and want the list to be part of a larger scrolling view. As it stands I get an embedded scroll view for the list which is not my intent. Thanks!
4
0
5.4k
Sep ’20
Scrolling image in SwiftUI
Hi, why doesn't this view scroll? The image is taller than the screen. struct ImageScroll: View {     @State var uiImage: UIImage     var body: some View {         ScrollView {             Image(uiImage: uiImage)                 .focusable()         }         .focusable()     } } Thanks, Spiff
1
0
1.2k
Dec ’20
ARCamera.trackingState changes to .initializing after device rotatio
Hi, after rotating the iPad ARCamera.trackingState transitions to .initilizing and the video freezes. The application as a whole still functions. I'm unable to extract a relevant code example as this is embedded in a larger application. I am not seeing this behavior on iPhone. Is there any possibility that this is related to layout constraints? I see some warnings when the rotation occurs. Is there anything else I might examine? Thank you
1
0
559
Jun ’21
SectionedFetchRequest mixes up the sections
I am presenting a list of Items which are sections by the categoryIdentifier property. My app uses CloudKit. When I add change the categoryIdentifier for an item it is display in the correct section and other running instances of the app do the same. When restarting the app some items are grouped under an incorrect section, but the cstegoryIdentifier within the item is still as it was set. My question is what I'm doing wrong that upon restart the organization is incorrect. In case it matters, I'm setting this in the container:         container.viewContext.automaticallyMergesChangesFromParent = true As an aside: It seems necessary to make the sectioning type optional (as is the case in the underlying entity) like this SectionedFetchResults<String?, Item> Though the examples don't seem to need this. struct ContentView: View {     @Environment(\.managedObjectContext) private var viewContext     @State private var isShowingItem = false     @State private var isAddingItem = false          @SectionedFetchRequest(         sectionIdentifier: \.categoryIdentifier,         sortDescriptors: [NSSortDescriptor(keyPath: \Item.name, ascending: true)],         animation: .default) private var sectionedItems: SectionedFetchResults<String?, Item>          var body: some View {         NavigationView {             List {                 ForEach(sectionedItems) { section in                     Section(header: Text(Category.nameForId(section.id, context: viewContext)).font(.headline)) {                         ForEach(section) { item in                             NavigationLink(destination: ItemInputView(item: item, category: Category.get(identifier: item.category, context: viewContext))) {                                 Text(item.getName())                             }                         }                     }                 }             }                          .navigationTitle("Foo")             .sheet(isPresented: $isAddingItem) {                 ItemInputView(item: nil, category: Category.getDefault(context: viewContext))             }         }         .navigationViewStyle(.stack)     } }
1
0
1.2k
Nov ’21
LPMetadataProvider errors
Using the code below to fetch data for multiple urls I encounter a number of errors such as: 2021-12-01 20:20:32.090690-0500 foo[63170:6750061] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}> 021-12-01 20:20:32.115662-0500 yerl[63170:6749861] [ProcessSuspension] 0x10baf8cc0 - ProcessAssertion: Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=63200, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit} I've added the following to my entitlements file:  <key>com.apple.security.network.client</key>     <true/> with no change in the result. I gather that these are errors from a WKWebView but don't know how to resolve them. @State private var metadataProvider: LPMetadataProvider? ... metadataProvider?.startFetchingMetadata(for: url) { (linkMetadata, error) in             guard let linkMetadata = linkMetadata, let imageProvider = linkMetadata.iconProvider else { return }             imageProvider.loadObject(ofClass: UIImage.self) { (fetchedImage, error) in                 if let error = error {                     print(error.localizedDescription)                     return                 }                 if let uiimage = fetchedImage as? UIImage {                     DispatchQueue.main.async {                         let image = Image(uiImage: uiimage)                         self.image = image                         print("cache: miss \(url.absoluteString)")                         model.set(uiimage, for: url)                     }                 } else {                     print("no image available for \(url.absoluteString)")                 }             }         } Thanks in advance.
2
0
1.6k
Dec ’21
error ‘Texture Descriptor Validation
My RealityKit app uses an ARView with camera mode .nonAR. Later it puts another ARView with camera mode .ar on top of this. When I apply layout constraints to the second view the program aborts with the follow messages. If both views are of type .ar this doesn't occur, it is only when the first view is .nonAR and then has the second presented over it. I have been unable so far to reproduce this behavior in a demo program to provide to you and the original code is complex and proprietary. Does anyone know what is happening? I've seen other questions concerning situation but not under the same circumstances. 2021-12-01 17:59:11.974698-0500 MyApp[10615:6672868] -[MTLTextureDescriptorInternal validateWithDevice:], line 1325: error ‘Texture Descriptor Validation MTLTextureDescriptor has width (4294967295) greater than the maximum allowed size of 16384. MTLTextureDescriptor has height (4294967295) greater than the maximum allowed size of 16384. MTLTextureDescriptor has invalid pixelFormat (0). ’ -[MTLTextureDescriptorInternal validateWithDevice:]:1325: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width (4294967295) greater than the maximum allowed size of 16384. MTLTextureDescriptor has height (4294967295) greater than the maximum allowed size of 16384. MTLTextureDescriptor has invalid pixelFormat (0).
3
0
2.9k
Dec ’21
Subclassed ARView crashes in init()
I am subclassing ARView. I'm seeing the following crash on Firebase during initialization. Unfortunately I can't reproduce it locally so I don't really know what is going on. All the devices are running iOS 15. Most of the devices have < 60 MB available RAM but not all, a few have more. It doesn't smell like a memory issue, but I mention it here... has anyone seen this? It crashes in this thread: Crashed: com.apple.root.default-qos EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000arrow_right 0 CoreRE re::CompoundShape::~CompoundShape() + 168 1 CoreRE re::CompoundShape::~CompoundShape() + 148 2 CoreRE re::CollisionShapeAssetLoader::unloadAsset(void*) + 176 3 CoreRE re::internal::AssetBackgroundLoader::unloadAsset(re::internal::AssetLoadItem&) + 168 4 CoreRE re::internal::AssetBackgroundLoader::runIfNeeded(re::internal::AssetLoadItem&) + 88 after starting on the main three: com.apple.main-thread0 ARKitCore +[ARSession setRenderType:] + 1022 2RealityKit ARView.init(frame:cameraMode:automaticallyConfigureSession:) + 740
2
0
848
Mar ’22
Move entity to center of nonAR view
I'm recreating the ARQuickLook controller in code. One of its behaviors is to move the model to the visible center when entering Obj mode. I've hacked the ARViewContainer of the default Xcode Augmented Reality App to demonstrate what I'm trying to do. I think that moving the entity to 0,0,0 will generally not do the right thing because the world origin will be elsewhere. What I'm not clear on is how to specify the translation for entity.move() in the code. I'm assuming I'll need to raycast using a CGPoint describing view center to obtain the appropriate translation but I'm not sure about the details. Thanks for any help with this. struct ARViewContainer: UIViewRepresentable { let arView = ARView(frame: .zero) let boxAnchor = try! Experience.loadBox() func makeUIView(context: Context) -> ARView { arView.scene.anchors.append(boxAnchor) return arView } func updateUIView(_ uiView: ARView, context: Context) { DispatchQueue.main.asyncAfter(deadline: .now() + 4) { arView.environment.background = .color(.white) arView.cameraMode = .nonAR if let entity = boxAnchor.children.first { let translation = SIMD3<Float>(x: 0, y: 0, z: 0 ) let transform = Transform(scale: .one, rotation: simd_quatf(), translation: translation) entity.move(to: transform, relativeTo: nil, duration: 2, timingFunction: .easeInOut) } } } }
5
0
1.9k
Mar ’22
Get coordinates of pivot point in ModelEntity
I'd like to know the location of the pivot point of a ModelEntity, is there any way to get this? Alternatively can I get it from a USDZ file? I want to place models in a specific location and some models have the pivot in the center while others have it at the bottom. If I can detect this I can adjust accordingly and place them correctly. I don't have control over the models, alas. Thanks, Spiff
3
0
1.8k
Apr ’22
Entity dimensions in RealityKit
I’m loading a USDZ model using Entity.loadAsync(contentsOf:) I’d like to get the dimensions of the model and I find that visualBounds(relativeTo: nil).extents returns dimensions larger than the actual dimensions while I see the correct dimensions when viewing the USDZ in Blender or when instantiating it as a MDLAsset(url:). What is the method to get the actual dimensions from an Entity? Thanks Thanks
2
0
1.4k
May ’22