Example project that sometimes(?) hangs when accessing SCSharableContent.current.
The await simply never returns. Rewriting to SCShareableContent.getWithCompletionHandler {} has the same issue, the completion handler never gets called.
This only happens occasionally. After developing a ScreenCaptureKit app for a while, and thus having started and killed many screen capture sessions.
Restarting the ReplayKit deamon "fixes" the problem:
launchctl kickstart -k gui/$(id -u)/com.apple.replayd
This can also be done from code:
let process = Process()
process.executableURL = URL(filePath: "/bin/launchctl")
process.arguments = ["kickstart", "-k", "gui/\(getuid())/com.apple.replayd"]
try process.run()
Alternatively, rebooting the computer also works.
Submitted as feedback to Apple with id: FB12114396, FB15779754
Nonstrict B.V., Mathijs Kadijk & Tom Lokhorst, released under MIT License.