【发布时间】:2016-08-02 07:09:25
【问题描述】:
我想使用 QuickTime Player 阻止每个应用程序的屏幕录制或视频输出。
我用UIScreen 检测到 hdmi 输出和播放。
但是没有检测到 QuickTime Player 视频录制。
如何检测 QuickTime Player?
谢谢。
【问题讨论】:
标签: ios quicktime screen-recording
我想使用 QuickTime Player 阻止每个应用程序的屏幕录制或视频输出。
我用UIScreen 检测到 hdmi 输出和播放。
但是没有检测到 QuickTime Player 视频录制。
如何检测 QuickTime Player?
谢谢。
【问题讨论】:
标签: ios quicktime screen-recording
因此不知道检测 QuickTime Player 录制。
但我找到了一个有技巧的解决方案。
如果 QuickTime Player 正在录制,则 AVAudioSession 的输出端口类型已更改为 HDMIOutput。
所以我编码如下......(Swift 2.2)
func checkOutputPortType() {
let asRoute = AVAudioSession.sharedInstance().currentRoute
for output in asRoute.outputs {
if output.portType == AVAudioSessionPortHDMI {
// something you want..
}
}
}
在 ViewDidLoad 中插入该函数并添加 AVAudioSessionRouteChangeNotification 通知。
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(checkOutputPortType), name: AVAudioSessionRouteChangeNotification, object: nil)
谢谢。
【讨论】:
在 iOS 11 中,您可以使用通知
NSNotification.Name.UIScreenCapturedDidChange
在AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NotificationCenter.default.addObserver(self, selector: #selector(checkIFScreenIsCapture), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil) ......
使用选择器
func checkIFScreenIsCapture(notification:Notification){
guard let screen = notification.object as? UIScreen else { return }
if screen.isCaptured == true {
}else{
}
}
【讨论】: