Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Realm
- APNs Key
- networking
- 열거형
- @Binding
- writeasync
- @ObservedObject
- Postman
- datepicker
- CaseIterable
- Comparable
- collectionview
- @State
- 회고
- UserInfo
- fscalendar
- PushNotification
- PageControl
- UserNofificationCenter
- apns
- RemoteNotification
- moya
- @EnvironmentObject
- Remote Notification
- FCM
- enum
- Alamofire
- IOS
- webview
- combine
Archives
- Today
- Total
conyang's iOS
[iOS] Push Notification 메소드 정리 본문
1. UserInfo
- 푸시 데이터가 담겨있는 저장소, [ AnyHashable : Any ]? 형태의 자료형입니다.
{
"aps": {
"alert": "test"
"badge": "1"
}
}
2. Push Notification 메소드 정리
1) 앱이 실행 중인 경우 (Foreground)
- userNotificationCenter(_:willPresent:withCompletionHandler:)
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
print(userInfo)
completionHandler([.alert, .badge, .sound])
}
2) 앱이 백그라운드인 경우 (Background) & 사용자가 푸시를 탭한 경우
- userNotificationCenter(_:didReceice:withCompletionHandler:)
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
print(userInfo)
// 여기서 처리
completionHandler()
}
3) 앱이 종료되어 있는 경우 (Terminated)
- application(_:didFinishLaunchingWithOptions:)
func application (_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let userInfo = (launchOptions?[.remoteNotification] as? [String: Any])
print(userInfo)
// 여기서 UserInfo와 DeepLink 처리
}
4) 앱이 종료되어 있을 때 (Terminated) 푸시를 탭한 경우
- application(_:didReceiveRemoteNotification:)
// 앱이 종료되었을 때 시스템 노티를 탭한 경우 이곳에서도 수신
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("앱 종료 후 알림 클릭")
print(userInfo)
}
'iOS' 카테고리의 다른 글
| [iOS] Moya를 사용한 Networking (0) | 2024.03.17 |
|---|---|
| [iOS] 푸시 알림에서 받은 url을 웹뷰에 띄우기, postman 푸시 테스트 (0) | 2024.03.15 |
| [iOS] FCM으로 Push Notification 구현하기 (0) | 2024.03.15 |
| [iOS] Remote Notification 개념 정리 (0) | 2024.03.15 |