@@ -32,6 +32,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3232 _ = container. resolve ( UserTimeZoneSyncHandler . self)
3333 _ = container. resolve ( WidgetSyncEventHandler . self)
3434 _ = container. resolve ( WidgetSessionSyncHandler . self)
35+ NotificationCenter . default. addObserver (
36+ self ,
37+ selector: #selector( handleSceneDidActivate) ,
38+ name: UIScene . didActivateNotification,
39+ object: nil
40+ )
41+ NotificationCenter . default. addObserver (
42+ self ,
43+ selector: #selector( handleRemoteNotificationRegistrationRequest) ,
44+ name: . didRequestRemoteNotificationRegistration,
45+ object: nil
46+ )
3547
3648 // 알림 권한 요청
3749 UNUserNotificationCenter . current ( ) . delegate = self
@@ -40,9 +52,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4052 self . logger. error ( " Notification authorization error " , error: error)
4153 } else {
4254 self . logger. info ( " Notification permission granted: \( granted) " )
43- DispatchQueue . main. async {
44- UIApplication . shared. registerForRemoteNotifications ( )
45- }
55+ NotificationCenter . default. post ( name: . didRequestFCMTokenSync, object: nil )
4656 }
4757 }
4858
@@ -63,13 +73,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6373 return true
6474 }
6575
76+ @objc private func handleSceneDidActivate( ) {
77+ NotificationCenter . default. post ( name: . didRequestFCMTokenSync, object: nil )
78+ }
79+
80+ @MainActor
81+ @objc private func handleRemoteNotificationRegistrationRequest( ) {
82+ UIApplication . shared. registerForRemoteNotifications ( )
83+ }
84+
6685 // APNs 등록 성공
6786 func application(
6887 _ application: UIApplication ,
6988 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
7089 ) {
7190 logger. info ( " APNs token: \( deviceToken. map { String ( format: " %02.2hhx " , $0) } . joined ( ) ) " )
72- container. resolve ( PushMessagingService . self) . setAPNSToken ( deviceToken)
91+ NotificationCenter . default. post (
92+ name: . didReceiveAPNSToken,
93+ object: nil ,
94+ userInfo: [ " deviceToken " : deviceToken]
95+ )
7396 }
7497
7598 // APNs 등록 실패
0 commit comments