티스토리 뷰
일반적으로 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
'Swift' 카테고리의 다른 글
| [swift] Enum (0) | 2019.03.29 |
|---|---|
| 정수값에 구분자를 넣어보자!! (0) | 2018.08.21 |
| urlencoded 방식으로 POST 요청 보내기 (1) | 2018.08.20 |
| collectionView paging 해보기! (5) | 2018.07.20 |
| url에 한글이 있을 경우 간단히 인코딩하는 방법 (1) | 2018.07.11 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- permission error
- xib
- ssh
- pagingView
- UIBarButtonItem
- CollectionView
- Coordinator
- IOS
- AVKit
- Cleancode
- AVFoundation
- TDD
- HLS
- NIB
- http live streaming
- Realm
- AssociatedObject
- Swift
- m3u8
- UIButton
- BaseViewController
- Design Pattern
- testing
- UIControl
- customAlertView
- carousel
- RECORDING
- Closure
- database
- Video
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
글 보관함
