Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 1fd8fe1

Browse files
Remove usages of deprecated 'utils.ios.getter' function #1324
1 parent ccd4878 commit 1fd8fe1

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

src/admob/admob.ios.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { device } from "tns-core-modules/platform/platform";
22
import { DeviceType } from "tns-core-modules/ui/enums/enums";
3-
import { ios as iOSUtils } from "tns-core-modules/utils/utils";
43
import { firebase } from "../firebase-common";
54
import { BannerOptions, InterstitialOptions, PreloadRewardedVideoAdOptions, ShowRewardedVideoAdOptions } from "./admob";
65
import { AD_SIZE, BANNER_DEFAULTS, rewardedVideoCallbacks } from "./admob-common";
@@ -26,7 +25,7 @@ export function showBanner(arg: BannerOptions): Promise<any> {
2625
firebase.admob.adView = null;
2726
}
2827

29-
BANNER_DEFAULTS.view = iOSUtils.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController.view;
28+
BANNER_DEFAULTS.view = UIApplication.sharedApplication.keyWindow.rootViewController.view;
3029
const settings = firebase.merge(arg, BANNER_DEFAULTS);
3130
_bannerOptions = settings;
3231
const view = settings.view;
@@ -61,8 +60,8 @@ export function showBanner(arg: BannerOptions): Promise<any> {
6160
adRequest.keywords = settings.keywords;
6261
}
6362

64-
firebase.admob.adView.rootViewController = iOSUtils.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController;
65-
// var statusbarFrame = iOSUtils.getter(UIApplication, UIApplication.sharedApplication).statusBarFrame;
63+
firebase.admob.adView.rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
64+
// var statusbarFrame = UIApplication.sharedApplication.statusBarFrame;
6665

6766
firebase.admob.adView.loadRequest(adRequest);
6867

@@ -141,7 +140,7 @@ export function showInterstitial(arg?: InterstitialOptions): Promise<any> {
141140
// if no arg is passed, the interstitial has probably been preloaded
142141
if (!arg) {
143142
if (firebase.admob.interstitialView) {
144-
firebase.admob.interstitialView.presentFromRootViewController(iOSUtils.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController);
143+
firebase.admob.interstitialView.presentFromRootViewController(UIApplication.sharedApplication.keyWindow.rootViewController);
145144
resolve();
146145
} else {
147146
reject("Please call 'preloadInterstitial' first");
@@ -158,7 +157,7 @@ export function showInterstitial(arg?: InterstitialOptions): Promise<any> {
158157
reject(error.localizedDescription);
159158
} else {
160159
// now we can safely show it
161-
firebase.admob.interstitialView.presentFromRootViewController(iOSUtils.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController);
160+
firebase.admob.interstitialView.presentFromRootViewController(UIApplication.sharedApplication.keyWindow.rootViewController);
162161
resolve();
163162
}
164163
CFRelease(delegate);
@@ -268,7 +267,7 @@ export function showRewardedVideoAd(arg?: ShowRewardedVideoAdOptions): Promise<a
268267
rewardedVideoCallbacks.onCompleted = arg.onCompleted;
269268
}
270269

271-
firebase.admob.rewardedAdVideoView.presentFromRootViewController(iOSUtils.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController);
270+
firebase.admob.rewardedAdVideoView.presentFromRootViewController(UIApplication.sharedApplication.keyWindow.rootViewController);
272271
resolve();
273272

274273
} catch (ex) {
@@ -315,7 +314,7 @@ function _getBannerType(size): any {
315314
// return kGADAdSizeSkyscraper;
316315
return {"size": {"width": 120, "height": 600}, "flags": 0};
317316
} else if (size === AD_SIZE.SMART_BANNER || size === AD_SIZE.FLUID) {
318-
const orientation = iOSUtils.getter(UIDevice, UIDevice.currentDevice).orientation;
317+
const orientation = UIDevice.currentDevice.orientation;
319318
const isIPad = device.deviceType === DeviceType.Tablet;
320319
if (orientation === UIDeviceOrientation.Portrait || orientation === UIDeviceOrientation.PortraitUpsideDown) {
321320
// return kGADAdSizeSmartBannerPortrait;

src/messaging/messaging.ios.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import * as application from "tns-core-modules/application/application";
21
import * 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";
43
import { 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";
124
import { MessagingOptions } from "../firebase";
5+
import { firebase } from "../firebase-common";
6+
import { firebaseUtils } from "../utils";
7+
import { IosInteractiveNotificationAction, IosInteractiveNotificationCategory, IosInteractiveNotificationType } from "./messaging";
138

149
let _notificationActionTakenCallback: Function;
1510
let _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

343337
export 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

351343
const updateUserInfo = userInfoJSON => {
@@ -367,7 +359,7 @@ const updateUserInfo = userInfoJSON => {
367359
};
368360

369361
function _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

483474
function _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

501492
function _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

Comments
 (0)