@@ -10,6 +10,7 @@ import {
1010 IosInteractiveNotificationType
1111} from "./messaging" ;
1212import { MessagingOptions } from "../firebase" ;
13+ import { DelegateObserver , SharedNotificationDelegate } from "nativescript-shared-notification-delegate" ;
1314
1415let _notificationActionTakenCallback : Function ;
1516let _pendingNotifications : Array < any > = [ ] ;
@@ -18,7 +19,7 @@ let _pushToken: any;
1819let _receivedPushTokenCallback : Function ;
1920let _receivedNotificationCallback : Function ;
2021let _registerForRemoteNotificationsRanThisSession = false ;
21- let _userNotificationCenterDelegate : UNUserNotificationCenterDelegateImpl ;
22+ let _userNotificationCenterDelegateObserver : FirebaseNotificationDelegateObserverImpl ;
2223let _messagingConnected : boolean = null ;
2324let _firebaseRemoteMessageDelegate : FIRMessagingDelegateImpl ;
2425let _showNotifications : boolean = true ;
@@ -407,7 +408,7 @@ function _registerForRemoteNotifications() {
407408 } ) ;
408409
409410 if ( _showNotifications ) {
410- _userNotificationCenterDelegate = UNUserNotificationCenterDelegateImpl . new ( ) . initWithCallback ( ( unnotification , actionIdentifier ?, inputText ?) => {
411+ _userNotificationCenterDelegateObserver = new FirebaseNotificationDelegateObserverImpl ( ( unnotification , actionIdentifier ?, inputText ?) => {
411412 // if the app is in the foreground then this method will receive the notification
412413 // if the app is in the background, and user has responded to interactive notification, then this method will receive the notification
413414 // if the app is in the background, and user views a notification, applicationDidReceiveRemoteNotificationFetchCompletionHandler will receive it
@@ -434,7 +435,7 @@ function _registerForRemoteNotifications() {
434435 }
435436 } ) ;
436437
437- curNotCenter . delegate = _userNotificationCenterDelegate ;
438+ SharedNotificationDelegate . addObserver ( _userNotificationCenterDelegateObserver ) ;
438439 }
439440
440441 if ( typeof ( FIRMessaging ) !== "undefined" ) {
@@ -546,25 +547,16 @@ function _addObserver(eventName, callback) {
546547 return NSNotificationCenter . defaultCenter . addObserverForNameObjectQueueUsingBlock ( eventName , null , NSOperationQueue . mainQueue , callback ) ;
547548}
548549
549- // see https://developer.apple.com/reference/usernotifications/unusernotificationcenterdelegate?language=objc
550- class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNotificationCenterDelegate {
551- public static ObjCProtocols = [ ] ;
552-
553- static new ( ) : UNUserNotificationCenterDelegateImpl {
554- if ( UNUserNotificationCenterDelegateImpl . ObjCProtocols . length === 0 && typeof ( UNUserNotificationCenterDelegate ) !== "undefined" ) {
555- UNUserNotificationCenterDelegateImpl . ObjCProtocols . push ( UNUserNotificationCenterDelegate ) ;
556- }
557- return < UNUserNotificationCenterDelegateImpl > super . new ( ) ;
558- }
550+ class FirebaseNotificationDelegateObserverImpl implements DelegateObserver {
551+ observerUniqueKey = "firebase-messaging" ;
559552
560553 private callback : ( unnotification : UNNotification , actionIdentifier ?: string , inputText ?: string ) => void ;
561554
562- public initWithCallback ( callback : ( unnotification : UNNotification , actionIdentifier ?: string , inputText ?: string ) => void ) : UNUserNotificationCenterDelegateImpl {
555+ constructor ( callback : ( unnotification : UNNotification , actionIdentifier ?: string , inputText ?: string ) => void ) {
563556 this . callback = callback ;
564- return this ;
565557 }
566558
567- public userNotificationCenterWillPresentNotificationWithCompletionHandler ( center : UNUserNotificationCenter , notification : UNNotification , completionHandler : ( p1 : UNNotificationPresentationOptions ) => void ) : void {
559+ public userNotificationCenterWillPresentNotificationWithCompletionHandler ( center : UNUserNotificationCenter , notification : UNNotification , completionHandler : ( p1 : UNNotificationPresentationOptions ) => void , next : ( ) => void ) : void {
568560 const userInfo = notification . request . content . userInfo ;
569561 const userInfoJSON = firebaseUtils . toJsObject ( userInfo ) ;
570562
@@ -582,7 +574,7 @@ class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNot
582574 }
583575 }
584576
585- public userNotificationCenterDidReceiveNotificationResponseWithCompletionHandler ( center : UNUserNotificationCenter , response : UNNotificationResponse , completionHandler : ( ) => void ) : void {
577+ public userNotificationCenterDidReceiveNotificationResponseWithCompletionHandler ( center : UNUserNotificationCenter , response : UNNotificationResponse , completionHandler : ( ) => void , next : ( ) => void ) : void {
586578 // let's ignore "dismiss" actions
587579 if ( response && response . actionIdentifier === UNNotificationDismissActionIdentifier ) {
588580 completionHandler ( ) ;
0 commit comments