7

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.

Rahul
  • 5,594
  • 7
  • 38
  • 92

1 Answers1

10

App Screen Sharing:

As per the new update in API docs you can capture Video & Audio of the screen through your app only.

enter image description here

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

Doc Ref: https://developer.apple.com/library/content/releasenotes/General/WhatsNewIniOS/Articles/iOS_11_0.html

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.

WWDC 2017 Session 606

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...

CodeChanger
  • 7,953
  • 5
  • 49
  • 80
  • 1
    I am interested in recording screen of iPhone not the screen of my App. I thought may be apple have provided some new API to do so after iOS11's screen recording feature. But thnks for your solution :) @CodeChanger – Rahul Jun 07 '17 at 07:47
  • 2
    yes for IOS 11 they added screen recording feature in Control centre but thats private API and unfortunately we can not access outside our app :( – CodeChanger Jun 07 '17 at 08:53
  • can I record screens if any app accesses camera, let's say user take snaps via snapchat and recording starts without letting the user know? It's for parental control. – StealthTrails Sep 14 '17 at 16:50
  • 1
    @CodeChanger: TeamViewer can do it, as you can see here: https://www.teamviewer.com/en/features/ios-screen-sharing/ How did they get access to the private API? – Flupp Sep 28 '17 at 16:02
  • @Flupp TeamViewer can't do it. what they can do is only one side: control a computer from an iphone by mirroring the display of the computer to the iphone. but not vice versa – yonez Nov 21 '17 at 08:29
  • @yonez TeamViewer states "users can share their iPhone or iPad screens live with any other desktop or mobile device". So yes, they can do it. – fishinear Aug 12 '18 at 15:27