现在在iOS 11上是否可以录制屏幕?

7

今天我看到了一些苹果提供的视频,可以在控制中心录制屏幕。

我很好奇这是否也适用于开发人员?

我谷歌搜索了一下,但没有找到任何相关的文档。有人能够对这个话题进行解释吗?


1
他们刚刚加入了屏幕录制功能,目前还没有提供API支持。 - Moin Shirazi
https://dev59.com/pqXja4cB1Zd3GeqPS42I#46497295 - TheNextman
1个回答

10

应用程序屏幕共享:

根据API文档的最新更新,您可以通过应用程序仅捕获屏幕的视频音频

enter image description here

RPScreenRecorder提供记录您的应用程序的音频和视频的共享记录器对象。

使用此类,您可以记录应用程序屏幕并通过iPhone麦克风绑定音频。

以下是一些可以使用的方法,以不同的选项记录屏幕。

访问共享记录器:

class func shared()

控制应用录制:

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

希望这能帮助您在应用程序中捕获屏幕。

参考链接:https://developer.apple.com/documentation/replaykit/rpscreenrecorder

文档参考:https://developer.apple.com/library/content/releasenotes/General/WhatsNewIniOS/Articles/iOS_11_0.html

发布较晚,但对于仍在搜索相关问题的人可能有用。

iPhone 屏幕共享:

我对共享屏幕进行了一些研究,并得出以下更新。

WWDC 2017 Session 606

涵盖了我们实际想要共享、广播或捕获 iOS 设备屏幕的所有详细信息,包括音频和视频。

Apple 推出了 ReplyKit2,用于屏幕捕捉和共享。

广播代码:

1. 创建 RPScreenRecorder 对象:

`let broadCastController = RPBroadcastController()`

`let recorder = RPScreenRecorder.shared()`

2. 使用 startBroadcasting() 方法来开始广播:

    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)
                }
            }
      }

使用下面的Activity Controller方法选择要广播的应用程序。

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. 使用 stopBroadcasting() 方法停止广播:

func stopBroadcasting() {
        broadCastController.finishBroadcast { error in
            if error == nil {
                print("Broadcast ended")
                self.broadcastEnded()
            }
        }
}

希望这次最新的更新会有所帮助!

稍后将更新更多内容...


1
我对记录 iPhone 屏幕而不是我的应用程序屏幕很感兴趣。我认为在 iOS11 的屏幕录制功能之后,苹果可能提供了一些新的 API 来实现这一点。但还是谢谢你的解决方案 :) @CodeChanger - Rahul
2
是的,对于IOS 11,他们在控制中心中添加了屏幕录制功能,但那是私有API,不幸的是我们无法在我们的应用程序之外访问它 :( - CodeChanger
如果任何应用程序访问摄像头,比如用户通过 Snapchat 拍照片并且录制屏幕开始而不让用户知道,那么我可以记录屏幕吗?这是为了家长控制。 - StealthTrails
1
@CodeChanger:TeamViewer可以做到,你可以在这里看到:https://www.teamviewer.com/en/features/ios-screen-sharing/ 他们是如何获得私有API的访问权限的? - Flupp
@Flupp TeamViewer做不到。他们能做的只有单向操作:通过将计算机的显示镜像到iPhone上,从iPhone控制计算机。但反过来则不行。 - yonez
TeamViewer表示“用户可以与任何其他桌面或移动设备实时共享其iPhone或iPad屏幕”。所以,是的,他们可以这样做。 - fishinear

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接