@@ -11,7 +11,7 @@ import {
11
11
EMAIL_SUBSCRIPTION_CHANGED ,
12
12
SMS_SUBSCRIPTION_CHANGED
13
13
} from './events' ;
14
- import { isValidCallback , checkIfInitialized } from './helpers' ;
14
+ import { isValidCallback , isObjectNonNull } from './helpers' ;
15
15
16
16
const RNOneSignal = NativeModules . OneSignal ;
17
17
const eventManager = new EventManager ( RNOneSignal ) ;
@@ -30,28 +30,28 @@ export default class OneSignal {
30
30
/* O B S E R V E R S */
31
31
32
32
static addPermissionObserver ( observer ) {
33
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
33
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
34
34
isValidCallback ( observer ) ;
35
35
RNOneSignal . addPermissionObserver ( ) ;
36
36
eventManager . addEventHandler ( PERMISSION_CHANGED , observer ) ;
37
37
}
38
38
39
39
static addSubscriptionObserver ( observer ) {
40
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
40
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
41
41
isValidCallback ( observer ) ;
42
42
RNOneSignal . addSubscriptionObserver ( ) ;
43
43
eventManager . addEventHandler ( SUBSCRIPTION_CHANGED , observer ) ;
44
44
}
45
45
46
46
static addEmailSubscriptionObserver ( observer ) {
47
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
47
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
48
48
isValidCallback ( observer ) ;
49
49
RNOneSignal . addEmailSubscriptionObserver ( ) ;
50
50
eventManager . addEventHandler ( EMAIL_SUBSCRIPTION_CHANGED , observer ) ;
51
51
}
52
52
53
53
static addSMSSubscriptionObserver ( observer ) {
54
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
54
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
55
55
isValidCallback ( observer ) ;
56
56
RNOneSignal . addSMSSubscriptionObserver ( ) ;
57
57
eventManager . addEventHandler ( SMS_SUBSCRIPTION_CHANGED , observer ) ;
@@ -67,14 +67,14 @@ export default class OneSignal {
67
67
* @param {function } handler
68
68
*/
69
69
static setNotificationWillShowInForegroundHandler ( handler ) {
70
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
70
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
71
71
isValidCallback ( handler ) ;
72
72
RNOneSignal . setNotificationWillShowInForegroundHandler ( ) ;
73
73
eventManager . setEventHandler ( NOTIFICATION_WILL_SHOW , handler ) ;
74
74
}
75
75
76
76
static setNotificationOpenedHandler ( handler ) {
77
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
77
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
78
78
isValidCallback ( handler ) ;
79
79
80
80
RNOneSignal . setNotificationOpenedHandler ( ) ;
@@ -84,18 +84,18 @@ export default class OneSignal {
84
84
/* R E G I S T R A T I O N E T C */
85
85
86
86
static promptForPushNotificationsWithUserResponse ( handler ) {
87
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
87
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
88
88
89
89
if ( Platform . OS === 'ios' ) {
90
90
isValidCallback ( handler ) ;
91
91
RNOneSignal . promptForPushNotificationsWithUserResponse ( handler ) ;
92
92
} else {
93
93
console . log ( "promptForPushNotificationsWithUserResponse: this function is not supported on Android" ) ;
94
94
}
95
- }
96
-
95
+ }
96
+
97
97
static registerForProvisionalAuthorization ( handler ) {
98
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
98
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
99
99
100
100
if ( Platform . OS === 'ios' ) {
101
101
isValidCallback ( handler ) ;
@@ -106,13 +106,13 @@ export default class OneSignal {
106
106
}
107
107
108
108
static disablePush ( disable ) {
109
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
109
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
110
110
111
111
RNOneSignal . disablePush ( disable ) ;
112
112
}
113
113
114
114
static unsubscribeWhenNotificationsAreDisabled ( unsubscribe ) {
115
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
115
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
116
116
117
117
if ( Platform . OS === 'android' ) {
118
118
RNOneSignal . unsubscribeWhenNotificationsAreDisabled ( unsubscribe ) ;
@@ -125,18 +125,18 @@ export default class OneSignal {
125
125
126
126
static isLocationShared ( ) {
127
127
// must return a promise
128
- if ( ! checkIfInitialized ( RNOneSignal ) ) return Promise . resolve ( ) ;
128
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return Promise . resolve ( ) ;
129
129
return RNOneSignal . isLocationShared ( ) ;
130
130
}
131
131
132
132
static setLocationShared ( shared ) {
133
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
133
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
134
134
135
135
RNOneSignal . setLocationShared ( shared ) ;
136
136
}
137
137
138
138
static promptLocation ( ) {
139
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
139
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
140
140
141
141
//Supported in both iOS & Android
142
142
RNOneSignal . promptLocation ( ) ;
@@ -148,7 +148,7 @@ export default class OneSignal {
148
148
* Gets the device state.
149
149
*/
150
150
static async getDeviceState ( ) {
151
- if ( ! checkIfInitialized ( RNOneSignal ) ) return Promise . resolve ( ) ;
151
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return Promise . resolve ( ) ;
152
152
const deviceState = await RNOneSignal . getDeviceState ( ) ;
153
153
154
154
if ( Platform . OS === 'android' ) {
@@ -162,7 +162,7 @@ export default class OneSignal {
162
162
/* T A G S */
163
163
164
164
static sendTag ( key , value ) {
165
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
165
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
166
166
167
167
if ( ! key || ( ! value && value !== "" ) ) {
168
168
console . error ( "OneSignal: sendTag: must include a key and a value" ) ;
@@ -176,7 +176,7 @@ export default class OneSignal {
176
176
}
177
177
178
178
static sendTags ( tags ) {
179
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
179
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
180
180
let keys = Object . keys ( tags ) ;
181
181
182
182
if ( keys . length === 0 ) {
@@ -193,20 +193,20 @@ export default class OneSignal {
193
193
}
194
194
195
195
static getTags ( callback ) {
196
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
196
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
197
197
RNOneSignal . getTags ( callback ) ;
198
198
}
199
199
200
200
static deleteTag ( key ) {
201
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
201
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
202
202
if ( typeof key !== "string" ) {
203
203
console . error ( "OneSignal: deleteTag: key argument must be of type string" ) ;
204
204
}
205
205
RNOneSignal . deleteTags ( [ key ] ) ;
206
206
}
207
207
208
208
static deleteTags ( tagKeys ) {
209
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
209
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
210
210
211
211
if ( ! Array . isArray ( tagKeys ) ) {
212
212
console . error ( "OneSignal: deleteTags: argument must be of array type" ) ;
@@ -218,7 +218,7 @@ export default class OneSignal {
218
218
/* E M A I L */
219
219
220
220
static setEmail ( email , emailAuthCode , handler ) {
221
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
221
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
222
222
223
223
if ( emailAuthCode === undefined )
224
224
emailAuthCode = null ;
@@ -230,7 +230,7 @@ export default class OneSignal {
230
230
}
231
231
232
232
static logoutEmail ( handler ) {
233
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
233
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
234
234
235
235
if ( ! handler )
236
236
handler = function ( ) { } ;
@@ -241,7 +241,7 @@ export default class OneSignal {
241
241
/* S M S */
242
242
243
243
static setSMSNumber ( smsNumber , smsAuthCode , handler ) {
244
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
244
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
245
245
246
246
if ( smsAuthCode === undefined )
247
247
smsAuthCode = null ;
@@ -253,7 +253,7 @@ export default class OneSignal {
253
253
}
254
254
255
255
static logoutSMSNumber ( handler ) {
256
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
256
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
257
257
258
258
if ( ! handler )
259
259
handler = function ( ) { } ;
@@ -264,7 +264,7 @@ export default class OneSignal {
264
264
/* N O T I F I C A T I O N S */
265
265
266
266
static postNotification ( notificationObjectString , onSuccess , onFailure ) {
267
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
267
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
268
268
269
269
if ( ! onSuccess )
270
270
onSuccess = function ( ) { } ;
@@ -276,7 +276,7 @@ export default class OneSignal {
276
276
}
277
277
278
278
static clearOneSignalNotifications ( ) {
279
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
279
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
280
280
281
281
if ( Platform . OS === 'android' ) {
282
282
RNOneSignal . clearOneSignalNotifications ( ) ;
@@ -286,7 +286,7 @@ export default class OneSignal {
286
286
}
287
287
288
288
static removeNotification ( id ) {
289
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
289
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
290
290
291
291
if ( Platform . OS === 'android' ) {
292
292
RNOneSignal . removeNotification ( id ) ;
@@ -296,7 +296,7 @@ export default class OneSignal {
296
296
}
297
297
298
298
static removeGroupedNotifications ( id ) {
299
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
299
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
300
300
301
301
if ( Platform . OS === 'android' ) {
302
302
RNOneSignal . removeGroupedNotifications ( id ) ;
@@ -308,7 +308,7 @@ export default class OneSignal {
308
308
/* E X T E R N A L U S E R I D */
309
309
310
310
static setExternalUserId ( externalId , varArg1 , varArg2 ) {
311
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
311
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
312
312
313
313
if ( typeof varArg1 === "function" ) {
314
314
RNOneSignal . setExternalUserId ( externalId , null , varArg1 ) ;
@@ -323,7 +323,7 @@ export default class OneSignal {
323
323
}
324
324
325
325
static removeExternalUserId ( handler ) {
326
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
326
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
327
327
328
328
if ( handler === undefined )
329
329
handler = function ( ) { } ;
@@ -334,7 +334,7 @@ export default class OneSignal {
334
334
/* I N A P P M E S S A G I N G */
335
335
336
336
static setInAppMessageClickHandler ( handler ) {
337
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
337
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
338
338
isValidCallback ( handler ) ;
339
339
RNOneSignal . initInAppMessageClickHandlerParams ( ) ;
340
340
RNOneSignal . setInAppMessageClickHandler ( ) ;
@@ -343,7 +343,7 @@ export default class OneSignal {
343
343
344
344
// Pass a String key and any value and creates a trigger map to pass to addTriggers()
345
345
static addTrigger ( key , value ) {
346
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
346
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
347
347
348
348
if ( ! key || ! value ) {
349
349
console . error ( "OneSignal: addTrigger: must include a key and a value" ) ;
@@ -357,7 +357,7 @@ export default class OneSignal {
357
357
358
358
// Expected format is Map<String, Object>, make sure all values are Objects and keys are Strings
359
359
static addTriggers ( triggers ) {
360
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
360
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
361
361
362
362
let keys = Object . keys ( triggers ) ;
363
363
@@ -369,76 +369,76 @@ export default class OneSignal {
369
369
}
370
370
371
371
static removeTriggersForKeys ( keys ) {
372
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
372
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
373
373
374
374
RNOneSignal . removeTriggersForKeys ( keys ) ;
375
375
}
376
376
377
377
static removeTriggerForKey ( key ) {
378
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
378
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
379
379
RNOneSignal . removeTriggerForKey ( key ) ;
380
380
}
381
381
382
382
static getTriggerValueForKey ( key ) {
383
383
// must return a promise
384
- if ( ! checkIfInitialized ( RNOneSignal ) ) return Promise . resolve ( ) ;
384
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return Promise . resolve ( ) ;
385
385
return RNOneSignal . getTriggerValueForKey ( key ) ;
386
386
}
387
387
388
388
static pauseInAppMessages ( pause ) {
389
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
389
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
390
390
RNOneSignal . pauseInAppMessages ( pause ) ;
391
391
}
392
392
393
393
/* O U T C O M E S */
394
394
395
395
static sendOutcome ( name , handler = function ( ) { } ) {
396
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
396
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
397
397
RNOneSignal . sendOutcome ( name , handler ) ;
398
398
}
399
399
400
400
static sendUniqueOutcome ( name , handler = function ( ) { } ) {
401
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
401
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
402
402
RNOneSignal . sendUniqueOutcome ( name , handler ) ;
403
403
}
404
404
405
405
static sendOutcomeWithValue ( name , value , handler = function ( ) { } ) {
406
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
406
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
407
407
RNOneSignal . sendOutcomeWithValue ( name , Number ( value ) , handler ) ;
408
408
}
409
409
410
410
/* P R I V A C Y C O N S E N T */
411
411
412
412
static userProvidedPrivacyConsent ( ) {
413
- if ( ! checkIfInitialized ( RNOneSignal ) ) return Promise . resolve ( ) ;
413
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return Promise . resolve ( ) ;
414
414
415
415
//returns a promise
416
416
return RNOneSignal . userProvidedPrivacyConsent ( ) ;
417
417
}
418
418
419
419
static requiresUserPrivacyConsent ( ) {
420
- if ( ! checkIfInitialized ( RNOneSignal ) ) return Promise . resolve ( ) ;
420
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return Promise . resolve ( ) ;
421
421
422
422
//returns a promise
423
423
return RNOneSignal . requiresUserPrivacyConsent ( ) ;
424
424
}
425
425
426
426
static setRequiresUserPrivacyConsent ( required ) {
427
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
427
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
428
428
429
429
RNOneSignal . setRequiresUserPrivacyConsent ( required ) ;
430
430
}
431
431
432
432
static provideUserConsent ( granted ) {
433
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
433
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
434
434
435
435
RNOneSignal . provideUserConsent ( granted ) ;
436
436
}
437
437
438
438
/* O T H E R F U N C T I O N S */
439
439
440
440
static setLogLevel ( nsLogLevel , visualLogLevel ) {
441
- if ( ! checkIfInitialized ( RNOneSignal ) ) return ;
441
+ if ( ! isObjectNonNull ( RNOneSignal ) ) return ;
442
442
443
443
RNOneSignal . setLogLevel ( nsLogLevel , visualLogLevel ) ;
444
444
}
0 commit comments