Reputation: 5844
Today I saw some videos that apple gave the option to record screen in control center.
I am curious if it is also available for developers or not?
I googled but didn't found any doc related to this. Can someone put some light on this topic.
Upvotes: 7
Views: 4022
Reputation: 8371
App Screen Sharing:
As per the new update in API docs you can capture Video & Audio of the screen through your app only.
RPScreenRecorder : The shared recorder object providing the ability to record audio and video of your app.
By this class, you can record your app screen and also bind audio through the iPhone microphone.
Below are some methods that you can use to record the screen with different options.
To Accessing the Shared Recorder:
class func shared()
To Controlling App Recording:
-- Starts recording the app display.
func startRecording(handler: ((Error?) -> Void)? = nil)
-- Stops the current recording.
func stopRecording(handler: ((RPPreviewViewController?, Error?) -> Void)? = nil)
-- Starts screen and audio capture.
func startCapture(handler: ((CMSampleBuffer, RPSampleBufferType, Error?) -> Void)?, completionHandler: ((Error?) -> Void)? = nil)
-- Stops screen capture
func stopCapture(handler: ((Error?) -> Void)? = nil)
Hope this will helps you to capture the screen in your app.
Ref Link: https://developer.apple.com/documentation/replaykit/rpscreenrecorder
Late Post but may be useful for those who are still searching related to this question.
iPhone Screen Sharing:
I have done some R&D on the sharing screen and come up with the below updates.
Covering all details that we actually want to share/broadcast or capture our iOS device screen with audio & videos.
Apple Introduce ReplyKit2 for screen capturing & sharing.
Code For Broadcasting:
1. Create Object of RPScreenRecorder:
`let broadCastController = RPBroadcastController()`
`let recorder = RPScreenRecorder.shared()`
2. Use startBroadcasting()
method to start broadcasting:
func startBroadcasting() {
RPBroadcastActivityViewController.load { broadcastAVC, error in
guard error == nil else {
print("Cannot load Broadcast Activity View Controller.")
return
}
if let broadcastAVC = broadcastAVC {
broadcastAVC.delegate = self
self.present(broadcastAVC, animated: true, completion: nil)
}
}
}
3. Use below activity Controller method to choose your app to broadcast.
func broadcastActivityViewController(_ broadcastActivityViewController: RPBroadcastActivityViewController,
didFinishWith broadcastController: RPBroadcastController?,
error: Error?) {
guard error == nil else {
print("Broadcast Activity Controller is not available.")
return
}
broadcastActivityViewController.dismiss(animated: true) {
broadcastController?.startBroadcast { error in
//TODO: Broadcast might take a few seconds to load up. I recommend that you add an activity indicator or something similar to show the user that it is loading.
if error == nil {
print("Broadcast started successfully!")
self.broadcastStarted()
}
}
}
}
4. Use stopBroadcasting()
method to Stop Broadcasting:
func stopBroadcasting() {
broadCastController.finishBroadcast { error in
if error == nil {
print("Broadcast ended")
self.broadcastEnded()
}
}
}
Hope this latest update will help!
Will update more soon...
Upvotes: 10