1- import * as application from "tns-core-modules/application/application" ;
21import * as applicationSettings from "tns-core-modules/application-settings" ;
3- import { ios as iOSUtils } from "tns-core-modules/utils/utils " ;
2+ import * as application from "tns-core-modules/application/application " ;
43import { device } from "tns-core-modules/platform/platform" ;
5- import { firebaseUtils } from "../utils" ;
6- import { firebase } from "../firebase-common" ;
7- import {
8- IosInteractiveNotificationAction ,
9- IosInteractiveNotificationCategory ,
10- IosInteractiveNotificationType
11- } from "./messaging" ;
124import { MessagingOptions } from "../firebase" ;
5+ import { firebase } from "../firebase-common" ;
6+ import { firebaseUtils } from "../utils" ;
7+ import { IosInteractiveNotificationAction , IosInteractiveNotificationCategory , IosInteractiveNotificationType } from "./messaging" ;
138
149let _notificationActionTakenCallback : Function ;
1510let _pendingNotifications : Array < any > = [ ] ;
@@ -235,9 +230,8 @@ export function registerForInteractivePush(model?: PushNotificationModel): void
235230 nativeCategories . push ( nativeCategory ) ;
236231 } ) ;
237232
238- const center = iOSUtils . getter ( UNUserNotificationCenter , UNUserNotificationCenter . currentNotificationCenter ) ;
239233 const nsSetCategories = < NSSet < UNNotificationCategory > > new NSSet ( < any > nativeCategories ) ;
240- center . setNotificationCategories ( nsSetCategories ) ;
234+ UNUserNotificationCenter . currentNotificationCenter ( ) . setNotificationCategories ( nsSetCategories ) ;
241235
242236 if ( model . onNotificationActionTakenCallback ) {
243237 _addOnNotificationActionTakenCallback ( model . onNotificationActionTakenCallback ) ;
@@ -341,11 +335,9 @@ export class NotificationActionResponse {
341335}
342336
343337export function areNotificationsEnabled ( ) {
344- let app = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) ;
345-
346338 // to check if also the app is registered use app.registeredForRemoteNotifications,
347339 // this below checks if user has enabled notifications for the app
348- return app . currentUserNotificationSettings . types > 0 ;
340+ return UIApplication . sharedApplication . currentUserNotificationSettings . types > 0 ;
349341}
350342
351343const updateUserInfo = userInfoJSON => {
@@ -367,7 +359,7 @@ const updateUserInfo = userInfoJSON => {
367359} ;
368360
369361function _registerForRemoteNotifications ( resolve ?, reject ?) {
370- let app = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) ;
362+ let app = UIApplication . sharedApplication ;
371363 if ( ! app ) {
372364 application . on ( "launch" , ( ) => _registerForRemoteNotifications ( resolve , reject ) ) ;
373365 return ;
@@ -385,11 +377,10 @@ function _registerForRemoteNotifications(resolve?, reject?) {
385377
386378 if ( parseInt ( device . osVersion ) >= 10 ) {
387379 const authorizationOptions = UNAuthorizationOptions . Alert | UNAuthorizationOptions . Sound | UNAuthorizationOptions . Badge ;
388- const curNotCenter = iOSUtils . getter ( UNUserNotificationCenter , UNUserNotificationCenter . currentNotificationCenter ) ;
389- curNotCenter . requestAuthorizationWithOptionsCompletionHandler ( authorizationOptions , ( granted , error ) => {
380+ UNUserNotificationCenter . currentNotificationCenter ( ) . requestAuthorizationWithOptionsCompletionHandler ( authorizationOptions , ( granted , error ) => {
390381 if ( ! error ) {
391382 if ( app === null ) {
392- app = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) ;
383+ app = UIApplication . sharedApplication ;
393384 }
394385 if ( app !== null ) {
395386 // see https://developer.apple.com/documentation/uikit/uiapplication/1623078-registerforremotenotifications
@@ -421,15 +412,15 @@ function _registerForRemoteNotifications(resolve?, reject?) {
421412 }
422413 }
423414
424- userInfoJSON . foreground = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) . applicationState === UIApplicationState . Active ;
415+ userInfoJSON . foreground = UIApplication . sharedApplication . applicationState === UIApplicationState . Active ;
425416
426417 _pendingNotifications . push ( userInfoJSON ) ;
427418 if ( _receivedNotificationCallback ) {
428419 _processPendingNotifications ( ) ;
429420 }
430421 } ) ;
431422
432- curNotCenter . delegate = _userNotificationCenterDelegate ;
423+ UNUserNotificationCenter . currentNotificationCenter ( ) . delegate = _userNotificationCenterDelegate ;
433424 }
434425
435426 if ( typeof ( FIRMessaging ) !== "undefined" ) {
@@ -444,7 +435,7 @@ function _registerForRemoteNotifications(resolve?, reject?) {
444435 userInfoJSON . body = asJs . body ;
445436 }
446437
447- const app = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) ;
438+ const app = UIApplication . sharedApplication ;
448439 if ( app . applicationState === UIApplicationState . Active ) {
449440 userInfoJSON . foreground = true ;
450441 if ( _receivedNotificationCallback ) {
@@ -481,7 +472,7 @@ function _addOnNotificationActionTakenCallback(callback: Function) {
481472}
482473
483474function _processPendingNotifications ( ) {
484- const app = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) ;
475+ const app = UIApplication . sharedApplication ;
485476 if ( ! app ) {
486477 application . on ( "launch" , ( ) => _processPendingNotifications ( ) ) ;
487478 return ;
@@ -499,7 +490,7 @@ function _processPendingNotifications() {
499490}
500491
501492function _processPendingActionTakenNotifications ( ) {
502- const app = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) ;
493+ const app = UIApplication . sharedApplication ;
503494 if ( ! app ) {
504495 application . on ( "launch" , ( ) => _processPendingNotifications ( ) ) ;
505496 return ;
0 commit comments