Skip to content

Commit

Permalink
Capture pixel screenshots implementation on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Reflejo committed Nov 5, 2024
1 parent 30539ad commit 29d6bcc
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions platform/swift/source/replay/SessionReplayTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@_implementationOnly import CapturePassable
import Foundation
import UIKit

final class SessionReplayTarget {
private let queue = DispatchQueue.serial(withLabelSuffix: "ReplayController", target: .default)
Expand Down Expand Up @@ -41,14 +42,28 @@ extension SessionReplayTarget: CapturePassable.SessionReplayTarget {
}

func captureScreenshot() {
// TODO: Implement
// DispatchQueue.main.async { [weak self] in
// self?.queue.async {
// self?.logger?.logSessionReplayScreenshot(
// screen: SessionReplayCapture(data: Data()),
// duration: 0
// )
// }
// }
DispatchQueue.main.async {
guard let window = UIApplication.shared.sessionReplayWindows().first else {
return
}

let layer = window.layer
let bounds = UIScreen.main.bounds.size

self.queue.async { [weak self] in
let start = Uptime()
let format = UIGraphicsImageRendererFormat()
format.scale = 1.0

let renderer = UIGraphicsImageRenderer(size: bounds, format: format)
let jpeg = renderer.jpegData(withCompressionQuality: 0.1) { context in
layer.render(in: context.cgContext)
}
self?.logger?.logSessionReplayScreenshot(
screen: SessionReplayCapture(data: jpeg),
duration: Uptime().timeIntervalSince(start)
)
}
}
}
}

0 comments on commit 29d6bcc

Please sign in to comment.