【问题标题】:iOS 11 Prevent Screen Record like NetflixiOS 11 阻止像 Netflix 一样的屏幕录制
【发布时间】:2022-02-18 16:57:38
【问题描述】:

我的应用程序中有视频正在播放,我不想被录制。 Netflix 应用程序所做的是在录制屏幕时让音频捕获而不是视频。

有人知道如何实现这个功能吗?

【问题讨论】:

  • 告诉我更多关于它的信息?您的问题缺乏解释。
  • 我只是不希望新的 iOS 功能 SCREEN RECORD 在我的应用程序播放视频时录制视频。Netflix 让您在他们的应用程序中录制视频,但只要您播放任何电影,他们只允许录制音频和视频他们只是在播放视频之前放置最后一个捕获视频帧

标签: iphone xcode cocoa-touch ios11 screen-recording


【解决方案1】:

您可以收听UIScreenCapturedDidChange 通知。

NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureChanged), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)

这在 iOS 11 屏幕录制开始和结束时调用。当用户录制屏幕时,您可以修改 UI 以阻止任何您不想录制的内容。

UIScreenisCaptured 属性更改时会触发此通知。您也可以自己检查此属性:

UIScreen.main.isCaptured

【讨论】:

    【解决方案2】:

    我相信,Netflix 充分利用了 Apple 提供的“FairPlay Streaming”技术。根据Apple Documentation

    如果您的应用程序使用 FairPlay Streaming (FPS) 您的视频内容 不会被 iOS 11 录屏自动捕获 macOS 上的功能或 QuickTime Player。您申请的部分 正在播放的内容会被黑掉。

    注意:FairPlay Streaming 只会为视频提供保护 您的部分内容。为防止捕获音频部分,您 仍应使用本文档中讨论的 UIScreen API 来 如果屏幕捕获开始,向用户提供适当的消息。

    可以通过以下链接深入了解FPS:

    https://developer.apple.com/streaming/fps/

    任何应用程序都可以加入 FPS 以获得与 Netflix 相同的结果。

    【讨论】:

      【解决方案3】:

      我创建了一个黑色视图并将其添加到 UIWindow 的顶部。然后,在 PlayerVideo 的视图控制器中,创建观察者

      NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureChanged), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)

      然后,在screenCaptureChanged

      (void) screenCaptureChanged {
      if (@available(iOS 11.0, *)) {
          BOOL isCaptured = [[UIScreen mainScreen] isCaptured];
      
          if (isCaptured) {
              self.blackView.hidden = false;
          }
          else {
              self.blackView.hidden = true;
          }
      }
      

      }

      此解决方案将在用户录制时阻止 PlayerVideo。但是,我想创建像 Netflix 那样的东西。我想让用户在看电影时为所欲为。如果他们正在录制,他们可以继续观看没有黑屏的视频。但是,当他们停止录制时,视频将以黑色视图保存。我仍在弄清楚 Netflix 是如何做到这一点的。

      【讨论】:

      【解决方案4】:

      Netflix 解决方案与代码无关。它被称为 DRM 或数字版权管理。它保护数据免受任何盗版。包括屏幕记录/截图和下载。伙计,它很贵。

      【讨论】:

        【解决方案5】:

        您只需在 Appdelegate.swift 页面中进行以下更改。

        当用户尝试记录屏幕时,它会自动在应用顶部添加一个模糊视图。

        weak var screen : UIView? = nil
        
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            NotificationCenter.default.addObserver(self, selector: #selector(preventScreenRecording), name: UIScreen.capturedDidChangeNotification, object: nil)
            return true
        }
        
        @objc func preventScreenRecording() {
            let isCaptured = UIScreen.main.isCaptured
            print("isCaptured: \(isCaptured)")
            if isCaptured {
                blurScreen()
            }
            else {
                removeBlurScreen()
            }
        }
        
        func blurScreen(style: UIBlurEffect.Style = UIBlurEffect.Style.regular) {
            screen = UIScreen.main.snapshotView(afterScreenUpdates: false)
            let blurEffect = UIBlurEffect(style: style)
            let blurBackground = UIVisualEffectView(effect: blurEffect)
            screen?.addSubview(blurBackground)
            blurBackground.frame = (screen?.frame)!
            window?.addSubview(screen!)
        }
        
        func removeBlurScreen() {
            screen?.removeFromSuperview()
        }
        

        【讨论】:

          猜你喜欢
          • 2018-03-02
          • 1970-01-01
          • 2017-09-18
          • 2023-03-16
          • 2012-02-16
          • 1970-01-01
          • 1970-01-01
          • 2021-09-27
          • 2012-03-01
          相关资源
          最近更新 更多