Skip to content

chore: add error message when not in production mode #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#cancelalllocalnotifications
*/
static cancelAllLocalNotifications() {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.cancelAllLocalNotifications();
}

Expand All @@ -117,6 +121,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#removealldeliverednotifications
*/
static removeAllDeliveredNotifications(): void {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.removeAllDeliveredNotifications();
}

Expand All @@ -128,6 +136,10 @@ class PushNotificationIOS {
static getDeliveredNotifications(
callback: (notifications: Array<Object>) => void,
): void {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.getDeliveredNotifications(callback);
}

Expand All @@ -137,6 +149,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#removedeliverednotifications
*/
static removeDeliveredNotifications(identifiers: Array<string>): void {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.removeDeliveredNotifications(identifiers);
}

Expand All @@ -146,6 +162,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#setapplicationiconbadgenumber
*/
static setApplicationIconBadgeNumber(number: number) {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.setApplicationIconBadgeNumber(number);
}

Expand All @@ -155,6 +175,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#getapplicationiconbadgenumber
*/
static getApplicationIconBadgeNumber(callback: Function) {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.getApplicationIconBadgeNumber(callback);
}

Expand All @@ -164,6 +188,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#cancellocalnotification
*/
static cancelLocalNotifications(userInfo: Object) {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.cancelLocalNotifications(userInfo);
}

Expand All @@ -173,6 +201,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#getscheduledlocalnotifications
*/
static getScheduledLocalNotifications(callback: Function) {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.getScheduledLocalNotifications(callback);
}

Expand Down Expand Up @@ -265,20 +297,22 @@ class PushNotificationIOS {
badge: boolean,
sound: boolean,
}> {
let requestedPermissions = {};
let requestedPermissions = {
alert: true,
badge: true,
sound: true,
};
if (permissions) {
requestedPermissions = {
alert: !!permissions.alert,
badge: !!permissions.badge,
sound: !!permissions.sound,
};
} else {
requestedPermissions = {
alert: true,
badge: true,
sound: true,
};
}
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
return RNCPushNotificationIOS.requestPermissions(requestedPermissions);
}

Expand All @@ -288,6 +322,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#abandonpermissions
*/
static abandonPermissions() {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.abandonPermissions();
}

Expand All @@ -299,6 +337,10 @@ class PushNotificationIOS {
*/
static checkPermissions(callback: Function) {
invariant(typeof callback === 'function', 'Must provide a valid callback');
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.checkPermissions(callback);
}

Expand All @@ -309,6 +351,10 @@ class PushNotificationIOS {
* See https://reactnative.dev/docs/pushnotificationios.html#getinitialnotification
*/
static getInitialNotification(): Promise<?PushNotificationIOS> {
invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
return RNCPushNotificationIOS.getInitialNotification().then(
notification => {
return notification && new PushNotificationIOS(notification);
Expand Down Expand Up @@ -372,6 +418,10 @@ class PushNotificationIOS {
}
this._remoteNotificationCompleteCallbackCalled = true;

invariant(
RNCPushNotificationIOS,
'PushNotificationManager is not available.',
);
RNCPushNotificationIOS.onFinishRemoteNotification(
this._notificationId,
fetchResult,
Expand Down