티스토리 뷰


일반적으로 notification을 등록할 때 notificationName을 만들어 사용하는 경우가 많았다.

NSNotificationName에는 이미 구현되있어 신기하고 편하게 가져다 쓰면 유용한 것들이 있었다.

그 중에 스크린샷을 찍었을 때 사용되는 notificationName이 있어서 간단히 사용해 보았다.


class ViewController: UIViewController {
  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    registerForNotifications()
  }
  
  deinit {
    NotificationCenter.default.removeObserver(self)
  }
  
  private func registerForNotifications() {
    NotificationCenter.default.addObserver(
      self
      , selector: #selector(performDidTask)
      , name: NSNotification.Name.UIApplicationUserDidTakeScreenshot
      , object: nil
    )
  }
  
  func performDidTask() {
    print("screenshot!!!!!")
  }
}


viewController가 초기화 될 때 notification을 등록하는 코드를 작성하고 스크린샷을 찍는 순간 "screenshot!!!!"이 출력되는 것을 볼 수 있었다!!!

시간이 지날 때마다 호출되는 notificationName이 있을것 같아 찾아 보았지만.... 보이지 않았다.... 내 눈에만 안보이는건 아니겠지....


다른 여러가지 notificationName은 아래 애플 공식 홈페이지에서 찾아보고 적용해볼 수 있다!!!



Apple 공식 홈피 - NSNotoficationName


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함