Skip to content

Commit aed903f

Browse files
authored
chore: add error message when not in production mode (#99)
1 parent 284ee74 commit aed903f

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

js/index.js

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class PushNotificationIOS {
108108
* See https://reactnative.dev/docs/pushnotificationios.html#cancelalllocalnotifications
109109
*/
110110
static cancelAllLocalNotifications() {
111+
invariant(
112+
RNCPushNotificationIOS,
113+
'PushNotificationManager is not available.',
114+
);
111115
RNCPushNotificationIOS.cancelAllLocalNotifications();
112116
}
113117

@@ -117,6 +121,10 @@ class PushNotificationIOS {
117121
* See https://reactnative.dev/docs/pushnotificationios.html#removealldeliverednotifications
118122
*/
119123
static removeAllDeliveredNotifications(): void {
124+
invariant(
125+
RNCPushNotificationIOS,
126+
'PushNotificationManager is not available.',
127+
);
120128
RNCPushNotificationIOS.removeAllDeliveredNotifications();
121129
}
122130

@@ -128,6 +136,10 @@ class PushNotificationIOS {
128136
static getDeliveredNotifications(
129137
callback: (notifications: Array<Object>) => void,
130138
): void {
139+
invariant(
140+
RNCPushNotificationIOS,
141+
'PushNotificationManager is not available.',
142+
);
131143
RNCPushNotificationIOS.getDeliveredNotifications(callback);
132144
}
133145

@@ -137,6 +149,10 @@ class PushNotificationIOS {
137149
* See https://reactnative.dev/docs/pushnotificationios.html#removedeliverednotifications
138150
*/
139151
static removeDeliveredNotifications(identifiers: Array<string>): void {
152+
invariant(
153+
RNCPushNotificationIOS,
154+
'PushNotificationManager is not available.',
155+
);
140156
RNCPushNotificationIOS.removeDeliveredNotifications(identifiers);
141157
}
142158

@@ -146,6 +162,10 @@ class PushNotificationIOS {
146162
* See https://reactnative.dev/docs/pushnotificationios.html#setapplicationiconbadgenumber
147163
*/
148164
static setApplicationIconBadgeNumber(number: number) {
165+
invariant(
166+
RNCPushNotificationIOS,
167+
'PushNotificationManager is not available.',
168+
);
149169
RNCPushNotificationIOS.setApplicationIconBadgeNumber(number);
150170
}
151171

@@ -155,6 +175,10 @@ class PushNotificationIOS {
155175
* See https://reactnative.dev/docs/pushnotificationios.html#getapplicationiconbadgenumber
156176
*/
157177
static getApplicationIconBadgeNumber(callback: Function) {
178+
invariant(
179+
RNCPushNotificationIOS,
180+
'PushNotificationManager is not available.',
181+
);
158182
RNCPushNotificationIOS.getApplicationIconBadgeNumber(callback);
159183
}
160184

@@ -164,6 +188,10 @@ class PushNotificationIOS {
164188
* See https://reactnative.dev/docs/pushnotificationios.html#cancellocalnotification
165189
*/
166190
static cancelLocalNotifications(userInfo: Object) {
191+
invariant(
192+
RNCPushNotificationIOS,
193+
'PushNotificationManager is not available.',
194+
);
167195
RNCPushNotificationIOS.cancelLocalNotifications(userInfo);
168196
}
169197

@@ -173,6 +201,10 @@ class PushNotificationIOS {
173201
* See https://reactnative.dev/docs/pushnotificationios.html#getscheduledlocalnotifications
174202
*/
175203
static getScheduledLocalNotifications(callback: Function) {
204+
invariant(
205+
RNCPushNotificationIOS,
206+
'PushNotificationManager is not available.',
207+
);
176208
RNCPushNotificationIOS.getScheduledLocalNotifications(callback);
177209
}
178210

@@ -265,20 +297,22 @@ class PushNotificationIOS {
265297
badge: boolean,
266298
sound: boolean,
267299
}> {
268-
let requestedPermissions = {};
300+
let requestedPermissions = {
301+
alert: true,
302+
badge: true,
303+
sound: true,
304+
};
269305
if (permissions) {
270306
requestedPermissions = {
271307
alert: !!permissions.alert,
272308
badge: !!permissions.badge,
273309
sound: !!permissions.sound,
274310
};
275-
} else {
276-
requestedPermissions = {
277-
alert: true,
278-
badge: true,
279-
sound: true,
280-
};
281311
}
312+
invariant(
313+
RNCPushNotificationIOS,
314+
'PushNotificationManager is not available.',
315+
);
282316
return RNCPushNotificationIOS.requestPermissions(requestedPermissions);
283317
}
284318

@@ -288,6 +322,10 @@ class PushNotificationIOS {
288322
* See https://reactnative.dev/docs/pushnotificationios.html#abandonpermissions
289323
*/
290324
static abandonPermissions() {
325+
invariant(
326+
RNCPushNotificationIOS,
327+
'PushNotificationManager is not available.',
328+
);
291329
RNCPushNotificationIOS.abandonPermissions();
292330
}
293331

@@ -299,6 +337,10 @@ class PushNotificationIOS {
299337
*/
300338
static checkPermissions(callback: Function) {
301339
invariant(typeof callback === 'function', 'Must provide a valid callback');
340+
invariant(
341+
RNCPushNotificationIOS,
342+
'PushNotificationManager is not available.',
343+
);
302344
RNCPushNotificationIOS.checkPermissions(callback);
303345
}
304346

@@ -309,6 +351,10 @@ class PushNotificationIOS {
309351
* See https://reactnative.dev/docs/pushnotificationios.html#getinitialnotification
310352
*/
311353
static getInitialNotification(): Promise<?PushNotificationIOS> {
354+
invariant(
355+
RNCPushNotificationIOS,
356+
'PushNotificationManager is not available.',
357+
);
312358
return RNCPushNotificationIOS.getInitialNotification().then(
313359
(notification) => {
314360
return notification && new PushNotificationIOS(notification);
@@ -372,6 +418,10 @@ class PushNotificationIOS {
372418
}
373419
this._remoteNotificationCompleteCallbackCalled = true;
374420

421+
invariant(
422+
RNCPushNotificationIOS,
423+
'PushNotificationManager is not available.',
424+
);
375425
RNCPushNotificationIOS.onFinishRemoteNotification(
376426
this._notificationId,
377427
fetchResult,

0 commit comments

Comments
 (0)