File tree 1 file changed +24
-9
lines changed
platform/swift/source/replay
1 file changed +24
-9
lines changed Original file line number Diff line number Diff line change 7
7
8
8
@_implementationOnly import CapturePassable
9
9
import Foundation
10
+ import UIKit
10
11
11
12
final class SessionReplayTarget {
12
13
private let queue = DispatchQueue . serial ( withLabelSuffix: " ReplayController " , target: . default)
@@ -41,14 +42,28 @@ extension SessionReplayTarget: CapturePassable.SessionReplayTarget {
41
42
}
42
43
43
44
func captureScreenshot( ) {
44
- // TODO: Implement
45
- // DispatchQueue.main.async { [weak self] in
46
- // self?.queue.async {
47
- // self?.logger?.logSessionReplayScreenshot(
48
- // screen: SessionReplayCapture(data: Data()),
49
- // duration: 0
50
- // )
51
- // }
52
- // }
45
+ DispatchQueue . main. async {
46
+ guard let window = UIApplication . shared. sessionReplayWindows ( ) . first else {
47
+ return
48
+ }
49
+
50
+ let layer = window. layer
51
+ let bounds = UIScreen . main. bounds. size
52
+
53
+ self . queue. async { [ weak self] in
54
+ let start = Uptime ( )
55
+ let format = UIGraphicsImageRendererFormat ( )
56
+ format. scale = 1.0
57
+
58
+ let renderer = UIGraphicsImageRenderer ( size: bounds, format: format)
59
+ let jpeg = renderer. jpegData ( withCompressionQuality: 0.1 ) { context in
60
+ layer. render ( in: context. cgContext)
61
+ }
62
+ self ? . logger? . logSessionReplayScreenshot (
63
+ screen: SessionReplayCapture ( data: jpeg) ,
64
+ duration: Uptime ( ) . timeIntervalSince ( start)
65
+ )
66
+ }
67
+ }
53
68
}
54
69
}
You can’t perform that action at this time.
0 commit comments