푸시 알림 데이터 이용
푸시 알림 메시지가 수신되거나 사용자에 의해 탭될 때 호출되는 메쏘드와 해당 상황에서 데이터를 추출하여 이용하는 방법에 대해 안내합니다.
딥링크 데이터 이용시 주의사항
앱이 포그라운드 상태일 때
// UNUserNotificationCenterDelegate 프로토콜 구현
@main
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
...
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("userInfo: \(notification.request.content.userInfo)")
if let rootDict = notification.request.content.userInfo as NSDictionary? {
if let jsonDict = rootDict["RW_push_payload_WP"] as? NSDictionary {
let title = jsonDict["RW_push_payload_TT"]
let body = jsonDict["RW_push_payload_BD"]
let deepLink = jsonDict["RW_push_payload_deeplink"]
print("Notification title: \(title), body: \(body), deepLink: \(deepLink)")
}
}
completionHandler([.sound, .badge])
}
...
}// 앱 포그라운드 상태일 때 알림
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)) {
NSDictionary *userInfo = notification.request.content.userInfo;
NSLog(@"푸시 데이터 : %@", userInfo);
NSDictionary *jsonDict = [dictionary objectForKey:@"RW_push_payload_WP"];
if (jsonDict != nil) {
String *title = [jsonDict objectForKey:@"RW_push_payload_TT"];
String *body = [jsonDict objectForKey:@"RW_push_payload_BD"];
String *deepLink = [jsonDict objectForKey:@"RW_push_payload_deeplink"];
NSLog("Notification title: %@, body: %@, deepLink: %@", title, body, deepLink);
}
completionHandler(UNNotificationPresentationOptionNone); // 포그라운드 상태에서 푸시왔을 때 푸시 마노출
// completionHandler(UNNotificationPresentationOptionAlert); // 포그라운드 상태에서 푸시왔을 때 푸시 노출
}jsonDict 에 포함된 데이터 Key/Value
최상위 Payload 키
Payload 값
필수여부
Payload 키
Payload 값
필수여부
앱이 백그라운드 상태일 때
Last updated
Was this helpful?