iOS 스크린샷 탐지?
앱스토어에 있는 앱 스냅챗은 자폭 사진이 있는 사진을 공유할 수 있는 앱입니다.X초 동안만 사진을 볼 수 있습니다.홈 전원 키 콤보를 사용하여 사진이 표시되는 동안 스크린샷을 찍으려고 하면 스크린샷을 찍으려 했다는 메시지가 보낸 사람에게 표시됩니다.
사용자가 스크린샷을 찍고 있음을 감지할 수 있는 SDK 부분은 무엇입니까?저는 이것이 가능한지 몰랐습니다.
iOS 7부터 다른 답은 더 이상 사실이 아닙니다.애플은 그렇게 만들었습니다.touchesCancelled:withEvent:사용자가 스크린샷을 찍을 때 더 이상 호출되지 않습니다.
이렇게 하면 Snapchat이 완전히 중단되므로 새로운 솔루션에 몇 가지 베타가 추가되었습니다.이제 이 솔루션은 NSNotification Center를 사용하여 UIApplicationUserDidTakeScreenshotNotification에 관찰자를 추가하는 것만큼 간단합니다.
다음은 예입니다.
목표 C
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
// executes after screenshot
}];
스위프트
NotificationCenter.default.addObserver(
forName: UIApplication.userDidTakeScreenshotNotification,
object: nil,
queue: .main) { notification in
//executes after screenshot
}
답을 찾았습니다!!스크린샷을 찍으면 화면에 표시되는 모든 터치가 중단됩니다.이것이 스냅챗이 사진을 보기 위해 홀딩이 필요한 이유입니다.참조: http://tumblr.jeremyjohnstone.com/post/38503925370/how-to-detect-screenshots-on-ios-like-snapchat
다음은 스위프트에서 마감하는 방법입니다.
func detectScreenShot(action: () -> ()) {
let mainQueue = NSOperationQueue.mainQueue()
NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationUserDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
// executes after screenshot
action()
}
}
detectScreenShot { () -> () in
print("User took a screen shot")
}
스위프트 4.2
func detectScreenShot(action: @escaping () -> ()) {
let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
// executes after screenshot
action()
}
}
이 기능은 다음에 표준 기능으로 포함되어 있습니다.
https://github.com/goktugyil/EZSwiftExtensions
고지 사항:제 레포입니다.
스위프트 4+
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: OperationQueue.main) { notification in
//you can do anything you want here.
}
이 관찰자를 사용하면 사용자가 스크린샷을 찍을 때 알 수 있지만 사용자를 막을 수는 없습니다.
최신 SWIFT 3:
func detectScreenShot(action: @escaping () -> ()) {
let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: .UIApplicationUserDidTakeScreenshot, object: nil, queue: mainQueue) { notification in
// executes after screenshot
action()
}
}
viewDidLoad에서 이 함수를 호출합니다.
detectScreenShot { () -> () in
print("User took a screen shot")
}
하지만,
NotificationCenter.default.addObserver(self, selector: #selector(test), name: .UIApplicationUserDidTakeScreenshot, object: nil)
func test() {
//do stuff here
}
아주 잘 작동합니다.메인 큐의 요점이 보이지 않습니다...
사용자가 사용자를 선택했는지 여부를 탐지할 수 있는 직접적인 방법은 없는 것 같습니다. home + power button에 따라이것은 다윈 알림을 사용하여 이전에 가능했지만 더 이상 작동하지 않습니다.스냅챗은 이미 하고 있기 때문에, 제 생각에는 그들이 아이폰 사진 앨범을 확인하여 이 10초 사이에 새로운 사진이 추가되었는지 여부를 감지하고 어떤 식으로든 현재 표시된 이미지와 비교하고 있는 것 같습니다.이 비교를 위해 일부 이미지 처리가 수행되었을 수 있습니다.생각해보면, 여러분은 이것을 확장해서 그것이 작동하도록 할 수 있을 것입니다.확인.자세한 내용은 여기를 참조하십시오.
편집:
UI 터치 취소 이벤트(화면 캡처로 터치가 취소됨)를 감지하고 이 블로그에 따라 사용자에게 다음 오류 메시지를 표시할 수 있습니다.iOS에서 스크린샷을 탐지하는 방법(예: SnapChat)
그런 경우에는 사용할 수 있습니다.– touchesCancelled:withEvent:이를 탐지하기 위해 UITouch 취소를 감지하는 방법.이 위임 방법에서 이미지를 제거하고 사용자에게 적절한 경고를 표시할 수 있습니다.
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
NSLog(@"Touches cancelled");
[self.imageView removeFromSuperView]; //and show an alert to the user
}
Swift 4의 예
클로저를 사용한 예제 #1
NotificationCenter.default.addObserver(forName: .UIApplicationUserDidTakeScreenshot,
object: nil,
queue: OperationQueue.main) { notification in
print("\(notification) that a screenshot was taken!")
}
선택기가 있는 예제 #2
NotificationCenter.default.addObserver(self,
selector: #selector(screenshotTaken),
name: .UIApplicationUserDidTakeScreenshot,
object: nil)
@objc func screenshotTaken() {
print("Screenshot taken!")
}
언급URL : https://stackoverflow.com/questions/13484516/ios-detection-of-screenshot
'programing' 카테고리의 다른 글
| 캐시와 세션의 이점 (0) | 2023.07.13 |
|---|---|
| Chrome localhost 쿠키가 설정되지 않음 (0) | 2023.07.13 |
| Oracle이 전날 기록 가져오기 (0) | 2023.07.13 |
| git 저장소에서 병합한 후 .orig 파일을 삭제하는 방법은 무엇입니까? (0) | 2023.07.13 |
| 다른 행을 기준으로 행 필터링 (0) | 2023.07.13 |