Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to build visionOS apps using Persona

How to build visionOS apps using Persona

iOS Engineer Meetup in Money Forward
https://moneyforward.connpass.com/event/323008

Akio Itaya

August 20, 2024
Tweet

More Decks by Akio Itaya

Other Decks in Programming

Transcript

  1. final class PersonaProvider: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { private let session =

    AVCaptureSession() private override init() { super.init() guard let device = AVCaptureDevice.systemPreferredCamera, let input = try? AVCaptureDeviceInput(device: device) else { return } #if targetEnvironment(simulator) #else session.addInput(input) #endif } }
  2. final class PersonaProvider: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { private let session =

    AVCaptureSession() private override init() { super.init() guard let device = AVCaptureDevice.systemPreferredCamera, let input = try? AVCaptureDeviceInput(device: device) else { return } #if targetEnvironment(simulator) #else session.addInput(input) #endif } }
  3. final class PersonaProvider: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { private let session =

    AVCaptureSession() private override init() { super.init() guard let device = AVCaptureDevice.systemPreferredCamera, let input = try? AVCaptureDeviceInput(device: device) else { return } #if targetEnvironment(simulator) #else session.addInput(input) #endif let output = AVCaptureVideoDataOutput() output.setSampleBufferDelegate(self, queue: DispatchQueue(label: "camera_queue")) session.addOutput(output) } }
  4. final class PersonaProvider: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { private let session =

    AVCaptureSession() private override init() { super.init() guard let device = AVCaptureDevice.systemPreferredCamera, let input = try? AVCaptureDeviceInput(device: device) else { return } #if targetEnvironment(simulator) #else session.addInput(input) #endif let output = AVCaptureVideoDataOutput() output.setSampleBufferDelegate(self, queue: DispatchQueue(label: "camera_queue")) session.addOutput(output) } func captureOutput(_ output: AVCaptureOutput, didOutput: CMSampleBuffer, from: AVCaptureConnection) { guard let imageBuffer = CMSampleBufferGetImageBuffer(didOutput) else { return } let ciImage = CIImage(cvImageBuffer: imageBuffer) let uiImage = UIImage(ciImage: ciImage) } }
  5. final class SessionContainer: NSObject, ObservableObject { private let session =

    MCSession(peer: peerId) private let nearbyServiceBrowser = MCNearbyServiceBrowser(peer: peerId, serviceType: serviceType) override init() { super.init() session.delegate = self nearbyServiceBrowser.delegate = self } } extension SessionContainer: MCNearbyServiceBrowserDelegate { } extension SessionContainer: MCSessionDelegate { }
  6. final class SessionContainer: NSObject, ObservableObject { private let session =

    MCSession(peer: peerId) private let nearbyServiceBrowser = MCNearbyServiceBrowser(peer: peerId, serviceType: serviceType) override init() { super.init() session.delegate = self nearbyServiceBrowser.delegate = self } } extension SessionContainer: MCNearbyServiceBrowserDelegate { func browser(_ browser: MCNearbyServiceBrowser, foundPeer: MCPeerID, withDiscoveryInfo: [String: String]?) { browser.invitePeer(foundPeer, to: session, withContext: nil, timeout: 30) } } extension SessionContainer: MCSessionDelegate { }
  7. final class SessionContainer: NSObject, ObservableObject { private let session =

    MCSession(peer: peerId) private let nearbyServiceBrowser = MCNearbyServiceBrowser(peer: peerId, serviceType: serviceType) private var selectedPeer: MCPeerID? override init() { super.init() session.delegate = self nearbyServiceBrowser.delegate = self } } extension SessionContainer: MCNearbyServiceBrowserDelegate { func browser(_ browser: MCNearbyServiceBrowser, foundPeer: MCPeerID, withDiscoveryInfo: [String: String]?) { browser.invitePeer(foundPeer, to: session, withContext: nil, timeout: 30) } } extension SessionContainer: MCSessionDelegate { func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) { selectedPeer = session.connectedPeers.first } }
  8. final class SessionContainer: NSObject, ObservableObject { private let session =

    MCSession(peer: peerId) private let nearbyServiceBrowser = MCNearbyServiceBrowser(peer: peerId, serviceType: serviceType) private var selectedPeer: MCPeerID? override init() { super.init() session.delegate = self nearbyServiceBrowser.delegate = self PersonaProvider.shared.updateFrame = { [weak self] image in if let self, let selectedPeer, let data = image.jpegData(compressionQuality: quality) { try? session.send(data, toPeers: [selectedPeer], with: .reliable) } } } } extension SessionContainer: MCNearbyServiceBrowserDelegate { func browser(_ browser: MCNearbyServiceBrowser, foundPeer: MCPeerID, withDiscoveryInfo: [String: String]?) { browser.invitePeer(foundPeer, to: session, withContext: nil, timeout: 30) } } extension SessionContainer: MCSessionDelegate { func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) { selectedPeer = session.connectedPeers.first } }