feat: 포그라운드 상태에서 FCM data-only 수신 시 인앱 팝업 표시

This commit is contained in:
Yu Sung 2025-04-22 18:44:05 +09:00
parent 79ab62fc31
commit c19b53767b
2 changed files with 35 additions and 10 deletions

View File

@ -46,16 +46,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Messaging.messaging().appDidReceiveMessage(userInfo) if let type = userInfo["type"] as? String, type == "POINT_GRANTED" {
// Print message ID. NotificationCenter.default.post(name: .pointGranted, object: userInfo["message"])
if let messageID = userInfo[gcmMessageIDKey] { } else {
DEBUG_LOG("Message ID: \(messageID)") Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
DEBUG_LOG("Message ID: \(messageID)")
}
// Print full message.
DEBUG_LOG("userInfo: \(userInfo)")
completionHandler(UIBackgroundFetchResult.newData)
} }
// Print full message.
DEBUG_LOG("userInfo: \(userInfo)")
completionHandler(UIBackgroundFetchResult.newData)
} }
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
@ -283,5 +287,6 @@ extension AppDelegate : UNUserNotificationCenterDelegate {
} }
extension Notification.Name { extension Notification.Name {
static let pointGranted = Notification.Name("POINT_GRANTED")
static let didReceiveHomeTab = Notification.Name("didReceiveHomeTab") static let didReceiveHomeTab = Notification.Name("didReceiveHomeTab")
} }

View File

@ -10,6 +10,9 @@ import SwiftUI
struct ContentView: View { struct ContentView: View {
@StateObject private var appState = AppState.shared @StateObject private var appState = AppState.shared
@State private var isShowDialog = false
@State private var message = ""
var body: some View { var body: some View {
ZStack { ZStack {
Color.black.ignoresSafeArea() Color.black.ignoresSafeArea()
@ -243,6 +246,23 @@ struct ContentView: View {
EmptyView() EmptyView()
.frame(width: 0, height: 0, alignment: .topLeading) .frame(width: 0, height: 0, alignment: .topLeading)
} }
if isShowDialog {
SodaDialog(
title: "포인트 지급",
desc: message,
confirmButtonTitle: "확인"
) {
isShowDialog = false
message = ""
}
}
}
.onReceive(NotificationCenter.default.publisher(for: .pointGranted)) {
if let msg = $0.object as? String {
self.message = msg
self.isShowDialog = true
}
} }
} }
} }