Post

Replies

Boosts

Views

Activity

VisionOS Enterprise API: fail to get cameraFrame in cameraFrameUpdates{}
I am developing an app based on visionOS and need to utilize the main camera access provided by the Enterprise API. I have applied for an enterprise license and added the main camera access capability and the license file in Xcode. In my code, I used await arKitSession.queryAuthorization(for: [.cameraAccess]) to request user permission for camera access. After obtaining the permission, I used arKitSession to run the cameraFrameProvider. However, when running for await cameraFrame in cameraFrameUpdates{ print("hello") guard let mainCameraSample = cameraFrame.sample(for: .left) else { continue } pixelBuffer = mainCameraSample.pixelBuffer } , I am unable to receive any frames from the camera, and even print("hello") within the braces do not execute. The app does not crash or throw any errors. Here is my full code: import SwiftUI import ARKit struct cameraTestView: View { @State var pixelBuffer: CVPixelBuffer? var body: some View { VStack{ Button(action:{ Task { await loadCameraFeed() } }){ Text("test") } if let pixelBuffer = pixelBuffer { let ciImage = CIImage(cvPixelBuffer: pixelBuffer) let context = CIContext(options: nil) if let cgImage = context.createCGImage(ciImage, from: ciImage.extent) { Image(uiImage: UIImage(cgImage: cgImage)) } }else{ Image("exampleCase") .resizable() .scaledToFill() .frame(width: 400,height: 400) } } } func loadCameraFeed() async { // Main Camera Feed Access Example let formats = CameraVideoFormat.supportedVideoFormats(for: .main, cameraPositions:[.left]) let cameraFrameProvider = CameraFrameProvider() let arKitSession = ARKitSession() // main camera feed access example var cameraAuthorization = await arKitSession.queryAuthorization(for: [.cameraAccess]) guard cameraAuthorization == [ARKitSession.AuthorizationType.cameraAccess:ARKitSession.AuthorizationStatus.allowed] else { return } do { try await arKitSession.run([cameraFrameProvider]) } catch { return } let cameraFrameUpdates = cameraFrameProvider.cameraFrameUpdates(for: formats[0]) if cameraFrameUpdates != nil { print("identify cameraFrameUpdates") } else{ print("fail to get cameraFrameUpdates") return } for await cameraFrame in cameraFrameUpdates! { print("hello") guard let mainCameraSample = cameraFrame.sample(for: .left) else { continue } pixelBuffer = mainCameraSample.pixelBuffer } } } #Preview(windowStyle: .automatic) { cameraTestView() } When I click the button, the console prints: identify cameraFrameUpdates It seems like it stuck in getting cameraFrame from cameraFrameUpdates. Occurring on VisionOS 2.0 Beta (just updated), Xcode 16 Beta 6 (just updated). Does anyone have a workaround for this? I would be grateful if anyone can help.
2
1
493
Aug ’24
VisionOS: .hoverEffect { effect.scaleEffect } breaking .fill()
A problem similar to https://developer.apple.com/forums/thread/761211 posted by @matti777. I was trying to implement the interaction of draggable point. When some point is activated, the color would change accordingly. When I define a .hoverEffect {} like below, the change of color in .fill() functionality stops working: struct DraggableCircleView: View { @Binding var position: CGPoint @Binding var activeIndex: Int var currentIndex: Int var radius:CGFloat = 20 var body: some View { Circle() .fill(activeIndex == currentIndex ? Color.blue : Color.white.opacity(0.1)) .frame(width: radius, height: radius) .hoverEffect(.highlight) // the issue occurred when the code below added: // .hoverEffect { effect, isactive, _ in // effect.scaleEffect(isactive ? 1.5 : 0.8) // } .position(position) .gesture( DragGesture() .onChanged { value in self.position = value.location activeIndex = currentIndex } ) .gesture( TapGesture() .onEnded({ activeIndex = currentIndex }) ) .transition(.opacity) .animation(.easeInOut, value: activeIndex) } } Occurring on VisionOS 2.0 Beta 4 SDK, Xcode 16 Beta 4. Does anyone have a workaround for this? I would really much like to have a hover scale effect for my draggable point. In addition, .hoverEffect(.highlight) does not break changes of fill color. Anyone interest in my full code can contact me and ask for it due to the post length limit.
2
0
286
Aug ’24