Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 271461e

Browse files
authored
fix popInitialNotification and null pointer
Fix a case where popInitialNotification is not triggered. Fix a null pointer exception.
1 parent 7589c4a commit 271461e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,30 @@ Notifications.configure = function(options) {
9595
this.isLoaded = true;
9696
}
9797

98-
const handlePopInitialNotification = function(state) {
98+
const handlePopInitialNotification = (state) => {
9999
if('active' !== state) {
100100
return;
101101
}
102102

103103
if (options.popInitialNotification === undefined || options.popInitialNotification === true) {
104104
this.popInitialNotification(function(firstNotification) {
105-
if ( firstNotification !== null ) {
106-
if(false === firstNotification.userInteraction || this.idInitialNotification === firstNotification.id) {
107-
return;
108-
}
109-
110-
this.idInitialNotification = firstNotification.id;
111-
this._onNotification(firstNotification, true);
105+
if (!firstNotification) {
106+
return;
112107
}
108+
109+
if(false === firstNotification.userInteraction || this.idInitialNotification === firstNotification.id) {
110+
return;
111+
}
112+
113+
this.idInitialNotification = firstNotification.id;
114+
this._onNotification(firstNotification, true);
113115
}.bind(this));
114116
}
115117
}
116118

117119
AppState.addEventListener('change', handlePopInitialNotification.bind(this));
118-
handlePopInitialNotification();
120+
121+
handlePopInitialNotification(AppState.currentState);
119122

120123
if ( options.requestPermissions !== false ) {
121124
this._requestPermissions();
@@ -499,7 +502,7 @@ Notifications.getScheduledLocalNotifications = function(callback) {
499502
soundName: notif.soundName,
500503
repeatInterval: notif.repeatInterval,
501504
id: notif.userInfo?.id,
502-
date: new Date(notif.fireDate),
505+
date: new Date(notif.fireDate),
503506
number: notif?.applicationIconBadgeNumber,
504507
message: notif?.alertBody,
505508
title: notif?.alertTitle,

0 commit comments

Comments
 (0)