LoginSignup
12
7

More than 5 years have passed since last update.

Screen Recordingの録画開始・停止を取得する

Last updated at Posted at 2017-08-04

iOS11で追加されるScreen Recordingを使うと映像コンテンツを録画することができてしまいます。リリースしたアプリの中に録画されるとマズいアプリがあったので、対応方法を探していたのですが、iOS11 beta4から対応できることになったので紹介します。

環境

Xcode9 beta 4
iOS11 beta 4

コード

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let screen = UIScreen.main
    screen.addObserver(self, forKeyPath: "captured", options: [.new, .old], context: nil)
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    guard let kp = keyPath else { return }

    if kp == "captured" {
        guard let ch = change else { return }

        let new = ch[NSKeyValueChangeKey.newKey] as! Bool
        let old = ch[NSKeyValueChangeKey.oldKey] as! Bool

        if new && !old {
            //録画開始
        } else if !new && old {
            //録画終了
        }
    }
}

参考サイト

developer forum

12
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
7