티스토리 뷰
[iOS] application(_:didReceiveRemoteNotification..)과 userNotificationCenter(_:didReceive..) 이 같이 있을 때 주의사항
eungding 2021. 6. 26. 01:20# notification을 눌렀을 때 들어오는 메소드
1) application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
- remote notification을 눌렀을 때 들어오는 메소드
2) userNotificationCenter(_:didReceive:withCompletionHandler:)
- remote, local notification을 눌렀을 때 들어오는 메소드
- iOS 10 이상부터 remote notification을 이 메소드로 처리하라고 권장함.
- Handling Notifications and Notification-Related Actions 문서에서는 항상 competionHandler() 를 콜하라고 적혀있음 (테스트 해보면 이 코드가 있고 없고 차이는 없긴 함..!)
⚠️ 주의사항 ⚠️
1. application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
2. userNotificationCenter(_:didReceive:withCompletionHandler:)
2번 없이 1번 메소드만 있을 때, remote notification을 누르면 1번이 잘 불림
하지만 두 메소드가 같이 있을 때, remote notification을 누르면 오직 2번 메소드만 불림!
(iOS 14.4에서 테스트해봄)
✔️ 결론 ✔️
iOS Deployment Target이 10이상이라면
userNotificationCenter(_:didReceive:withCompletionHandler:) 이 메소드 하나만 쓰고
이 안에서 local, remote 알림을 분기해서 특정 화면으로 랜딩하는 등의 작업을 해줘야함.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
let identifier = response.notification.request.identifier
// remote, local notification 구분 후, do something!
...
completionHandler()
}
Reference
https://stackoverflow.com/questions/46758030/in-which-method-should-i-handle-ios-remote-notification
In which method should I handle iOS remote notification?
I know similar questions have been asked many times. But it is still very confusing to me after reading those threads, especially after UNUserNotificationCenter is introduced in iOS 10. The official
stackoverflow.com
https://stackoverflow.com/questions/39382852/didreceiveremotenotification-not-called-ios-10
didReceiveRemoteNotification not called, iOS 10
In iOS 9.3, the didReceiveRemoteNotification method gets called on both of the following occasions. 1) When the push notification is received 2) When the user launches the app by tapping on the
stackoverflow.com
'🍏 > iOS' 카테고리의 다른 글
[iOS] iPad에서 Keyboard Navigation 으로 포커스 이동하기 (2) | 2021.07.08 |
---|---|
[iOS] DateFormat > Hour > hh / h / HH / H 차이 (0) | 2021.07.05 |
[iOS] Provisioning Profile 헷갈리는 것 정리 (1) | 2021.06.01 |
[iOS] Local Notification (0) | 2021.05.31 |
[iOS] XCode Template + install script 만들기 (0) | 2021.04.16 |
- Total
- Today
- Yesterday
- Watch App for iOS App vs Watch App
- flutter 앱 출시
- Dart Factory
- Flutter Spacer
- flutter deep link
- flutter dynamic link
- PencilKit
- Flutter 로딩
- DRF APIException
- Django Heroku Scheduler
- flutter build mode
- 플러터 얼럿
- METAL
- ipad multitasking
- SerializerMethodField
- Django Firebase Cloud Messaging
- Python Type Hint
- cocoapod
- drf custom error
- 장고 URL querystring
- ribs
- Flutter Clipboard
- 플러터 싱글톤
- Flutter Text Gradient
- Django FCM
- github actions
- Flutter getter setter
- Sketch 누끼
- 구글 Geocoding API
- 장고 Custom Management Command
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |