【Swift4】iOS에서 유저가 스크린샷을 찍으면 뭔가 한다【소 재료】
사용자가 스크린샷을 찍었음을 감지
 Swift3, Swift4
Swift3, Swift4 에서는, NSNotification 의 Name 구조체에 static인 프로퍼티로서 이하가 정의되고 있습니다.
static let UIApplicationUserDidTakeScreenshot: NSNotification.Name
여기를 notificationName으로 NotificationCenter의 observer를 넣어,
「홈 버튼+전원 버튼의 동시 누름」에 의한 스크린 샷을 찍은 것을 검지할 수 있습니다.
import UIKit
class MyViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Observerとして登録
        NotificationCenter.default.addObserver(self, selector: #selector(MyViewController.userDidTakeScreenshot(_:)), name: .UIApplicationUserDidTakeScreenshot, object: nil)
    }
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    // UIApplicationUserDidTakeScreenshot の通知を受けて実行される
    func userDidTakeScreenshot(notification: Notification) {
        // 何かする
    }
}
레퍼런스에도 쓰고 있습니다만, 통지를 받았을 때의 Notification의 userInfo에는 특별히 아무것도 설정되어 있지 않기 때문에, 상기의 예로 userDidTakeScreenshot 메소드내에서 notification.userInfo 로서도 nil이 돌려주어 옵니다.
 Swift2
let UIApplicationUserDidTakeScreenshotNotification: String
Swift2에서는 위와 같은 String 형의 정수가 정의되고 있습니다.
 예
import UIKit
class MyViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Observerとして登録
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyViewController.userDidTakeScreenshot(_:)), name: UIApplicationUserDidTakeScreenshotNotification, object: nil)
    }
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    // UIApplicationUserDidTakeScreenshotNotification の通知を受けて実行される
    func userDidTakeScreenshot(notification: NSNotification) {
        // 何かする
    }
}
 응용
이 알림을 이용하여
스크린 샷을 찍은 후에 경고를 내거나 사용자가 찍은 스크린 샷을 가져 와서 가공 한 것을 새롭게 보존시키는 등이 가능합니다.
참고:
 h tp // w w. 및 y.p. 오 rg / 아 r ゔ ぇ s / 1633
또한 앱의 내용에 따라 사용자가 얼마나 스크린샷을 찍고 있는지 로그를 찍는 것도 좋을지도 모릅니다.
 주의점
static let UIApplicationUserDidTakeScreenshot: NSNotification.Name
import UIKit
class MyViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Observerとして登録
        NotificationCenter.default.addObserver(self, selector: #selector(MyViewController.userDidTakeScreenshot(_:)), name: .UIApplicationUserDidTakeScreenshot, object: nil)
    }
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    // UIApplicationUserDidTakeScreenshot の通知を受けて実行される
    func userDidTakeScreenshot(notification: Notification) {
        // 何かする
    }
}
let UIApplicationUserDidTakeScreenshotNotification: String
import UIKit
class MyViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Observerとして登録
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyViewController.userDidTakeScreenshot(_:)), name: UIApplicationUserDidTakeScreenshotNotification, object: nil)
    }
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    // UIApplicationUserDidTakeScreenshotNotification の通知を受けて実行される
    func userDidTakeScreenshot(notification: NSNotification) {
        // 何かする
    }
}
이 알림을 이용하여
스크린 샷을 찍은 후에 경고를 내거나 사용자가 찍은 스크린 샷을 가져 와서 가공 한 것을 새롭게 보존시키는 등이 가능합니다.
참고:
h tp // w w. 및 y.p. 오 rg / 아 r ゔ ぇ s / 1633
또한 앱의 내용에 따라 사용자가 얼마나 스크린샷을 찍고 있는지 로그를 찍는 것도 좋을지도 모릅니다.
주의점
끝
이상, 사용 장소는 한정됩니다만, 원래 스쿠쇼의 검출은 할 수 없다고 생각하고 있었으므로 참고 정도에 썼습니다.
모르는 것이 아직도 많이 있고 재미 있습니다 
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(【Swift4】iOS에서 유저가 스크린샷을 찍으면 뭔가 한다【소 재료】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/taji-taji/items/2e28f71721fcdd12bc4d
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Reference
이 문제에 관하여(【Swift4】iOS에서 유저가 스크린샷을 찍으면 뭔가 한다【소 재료】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/taji-taji/items/2e28f71721fcdd12bc4d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)