PushNotification.popInitialNotification return repetitive notification.even if I first call Notifications.clearAllNotifications and then call PushNotification.popInitialNotification, this method return previous notification.
I'm confused.
please help me.
Hi @samaneh-kamalian
Can you be more precise ?
popInitialNotification aims to give you the notification which has opened the Application.
When a user press a notification, it opens the application and popInitialNotification will give you this notification pressed by user.
When clearAllLocalNotifications remove all notifications in the user notification center and scheduled notifications.
Regards,
1-because react-native-push-notification must configure out of life cycle of react-native,I use this module:
export default class PushController
{
static init() {
PushController.onNotification = null
}
static setCallbacks(onNotification) {
PushController.onNotification = onNotification
}
static configure() {
PushNotification.configure({
onRegister: (JsonToken) => {
let token = JsonToken.token;
log.debug("TOKEN:"+token);
keychain.storeItem("FirebaseToken", token).then((state) => {
if (!state) {
log.error("pushController:keychain.storeItem(firebasetoken):" + error);
}
})
},
onNotification: (notification) => {
if (PushController.onNotification) {
PushController.onNotification(notification)
}
else {
console.warn("PushController.onNotification is null");
}
},
senderID: "44444444444",
requestPermissions: true
})
}
}
and call configure method in index.js .
To be accountable to your work to pushes I call setCallbacks method in componentDidMount of my application main page and handle it.
But the problem is that when app is in background or closed and one push message receive and user press it on notification center, this callback does not called. so I use PushNotification.popInitialNotification( beside of setCallbacks) to answer this type of notification.
When user answer to push message I user resetAction to back to main page so componenetDidMount call again and PushNotification.popInitialNotification call again(I must do this because I want answer to other pushes if there are.).
In this step PushNotification.popInitialNotification return same notification, while I expect return null so my app fall to a closed loop .
I use clearAllNotifications to remove all notification and I expect after that PushNotification.popInitialNotification returns null, but does same work.
2- my other problem is that when my app is open and one push notification receive, I handle it, but this push notification is still remain in my notification centre and call clearAllNotifications does not clear my notification center.
I am not a native English speaker, I apologize for my bad English.
thanks a lot for your reply.
When user answer to push message I user resetAction to back to main page so componenetDidMount call again and PushNotification.popInitialNotification call again(I must do this because I want answer to other pushes if there are.).
I don't understand this part, If this is set to componentDidMount of the application/root element, this should not be called twice, I think you should check this start to avoid multiple call to this function.
2- my other problem is that when my app is open and one push notification receive, I handle it, but this push notification is still remain in my notification centre and call clearAllNotifications does not clear my notification center.
Did you check the that .cancelAllLocalNotifications() is called ?
If yes, I think it's a bug in the library (heterogeneous behaviour by reading the codebase) you can use the following method:
PushNotificationIOS.removeAllDeliveredNotifications();
link to the documentation removeAllDeliveredNotifications
It's installed with this library.
I don't understand this part, If this is set to
componentDidMountof the application/root element, this should not be called twice, I think you should check this start to avoid multiple call to this function.
I wanted when user pressed one notification and my app showed the push detail to her, if there were other notifications, my app automatically show those pushes to user.
Now, I think you said right, and I do not show other notifications to user automatically.
thanks for your suggestion.
Did you check the that .cancelAllLocalNotifications() is called ?
yes I checked it. but it did not clear notifications.
and my app is currently for Android so I can not use this PushNotificationIOS.removeAllDeliveredNotifications() method.
yes I checked it. but it did not clear notifications.
and my app is currently for Android so I can not use this PushNotificationIOS.removeAllDeliveredNotifications() method.
In the log from Android (adb logcat) do you see any error when you call .cancelAllLocalNotifications() ?
You should see:
Clearing alerts from the notification centre
In the application's logs. Following line
04-17 20:46:58.142 1512 2364 W ActivityManager: Unable to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x11000010 pkg=com.myapp (has extras) } U=0: not found
04-17 20:46:58.300 2051 2051 D NotificationListener: onNotificationPosted: StatusBarNotification(pkg=com.myapp user=UserHandle{0} id=Û±Û²Û²Û¶Û·Û²Û´Û²Û¹Û· tag=null key=0|com.myapp|1226724297|null|10275: Notification(channel=rn-push-notification-channel-id pri=1 contentView=null vibrate=null sound=null defaults=0x4 flags=0x10 color=0x00000000 category=call vis=PRIVATE))
04-17 20:46:58.561 31588 31588 I chatty : uid=10275(com.myapp) identical 11 lines
04-17 20:47:51.385 3550 13946 D PowerCalculator: topApCounter com.myapp
this is output of adb logcat when a push receive and cancelAllLocalNotifications() called
04-17 20:46:58.142 1512 2364 W ActivityManager: Unable to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x11000010 pkg=com.myapp (has extras) } U=0: not found 04-17 20:46:58.300 2051 2051 D NotificationListener: onNotificationPosted: StatusBarNotification(pkg=com.myapp user=UserHandle{0} id=Û±Û²Û²Û¶Û·Û²Û´Û²Û¹Û· tag=null key=0|com.myapp|1226724297|null|10275: Notification(channel=rn-push-notification-channel-id pri=1 contentView=null vibrate=null sound=null defaults=0x4 flags=0x10 color=0x00000000 category=call vis=PRIVATE)) 04-17 20:46:58.561 31588 31588 I chatty : uid=10275(com.myapp) identical 11 lines 04-17 20:47:51.385 3550 13946 D PowerCalculator: topApCounter com.myappthis is output of adb logcat when a push receive and cancelAllLocalNotifications() called
and this is log if app was closed and push received and in PushNotification.popInitialNotification call cancelAllLocalNotification() method.
04-17 21:06:03.817 4295 4394 W ReactNativeJS: collapse_key: 'com.myapp',
04-17 21:06:03.889 1512 2823 E InputDispatcher: Window handle Window{a6402fe u0 com.myapp/com.myapp.MainActivity} has no registered input channel
04-17 21:06:04.638 4295 4394 W ReactNativeJS: collapse_key: 'com.myapp',
04-17 21:06:04.789 4295 4295 I chatty : uid=10275(com.myapp) identical 2 lines
04-17 21:06:04.892 4295 4295 I chatty : uid=10275(com.myapp) identical 1 line
04-17 21:06:05.268 4295 4394 W ReactNativeJS: collapse_key: 'com.myapp',
04-17 21:06:05.844 4295 4394 W ReactNativeJS: collapse_key: 'com.myapp',
04-17 21:06:06.141 4295 4295 I chatty : uid=10275(com.myapp) identical 12 lines
04-17 21:06:06.403 4295 4394 W ReactNativeJS: collapse_key: 'com.myapp',
04-17 21:06:07.122 4295 4394 W ReactNativeJS: collapse_key: 'com.myapp',
04-17 21:06:07.904 4295 4394 W ReactNativeJS: collapse_key: 'com.myapp',
04-17 21:06:08.334 1512 1542 I ActivityManager: Killing 4295:com.myapp/u0a275 (adj 905): remove task
04-17 21:06:08.448 1512 1946 W InputDispatcher: channel 'a0850c9 com.myapp/com.myapp.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
04-17 21:06:08.448 1512 1946 E InputDispatcher: channel 'a0850c9 com.myapp/com.myapp.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
04-17 21:06:08.450 1512 9309 I WindowManager: WIN DEATH: Window{a0850c9 u0 com.myapp/com.myapp.MainActivity}
04-17 21:06:08.450 1512 9309 W InputDispatcher: Attempted to unregister already unregistered input channel 'a0850c9 com.myapp/com.myapp.MainActivity (server)'
Thanks for this feed back, can you provide the manifest.xml ? (at least the notification part)
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> -->
<!-- <uses-permission android:name="android.permission.VIBRATE"/> -->
<!-- <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/> -->
<!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> -->
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme">
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="my_channel" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description" android:value="channel_description" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@android:color/white" />
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService" />
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:screenOrientation="portrait" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
I think you can try without this part:
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
I think you can try without this part:
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver>
thanks a lot. this solve my problem and remove push from notification centre.
but my first problem is still remain, because for showing push page I must restAction from main page to push page(because I want push page be on top.) .
so when user reply to push message and back to main page, componentDidMount call again and PushNotification.popInitialNotification return repetitive notification.
If I call clearAllNotifications before go to main page(from push page) error occur and in bundle print this :
"GET /pages/pushNotification.page.js HTTP/1.1" 404 169 "-" "okhttp/3.12.1"
::ffff:127.0.0.1 - - [17/Apr/2020:18:08:26 +0000] "GET /pages/pushNotification.page.js HTTP/1.1" 404 169 "-" "okhttp/3.12.1"
I do not know what is this problem!
if I set clearAllNotifications before go to push page it clear my notification parameter!!!!
PushController.setCallbacks(this.handleOnPushNotification);
PushNotification.popInitialNotification((notification) => {
if (notification) {
PushNotification.clearAllNotifications();
this.handleOnPushNotification(notification);
}
if I set it after this.handleOnPushNotification(notification); it does not clear notification.
I cannot answer you on this point without context / code...
For your issue with componentDidMount, even if you use need to have restAction you should have an element on top of that, so you should put you logic with componentDidMount in this parent element
Then you store the notification where you want/can (to test you can use a global variable then refactor). Use it in restAction to pop push page and then clear the notification from application memory (global variable = null ?).
In your opinion
why clearAllNotifications() remove notification that I already set it in notification variable?
clearAllLocalNotification remove all scheduled notifications then clear the notification center, but it doesn’t aim to remove initial notification.
Initial notification is not a pending scheduled notification and is not related to the notification center (not the same thing/goal)
finally I solved my problem in this way: store notification that get from popInitialNotification in global variable and when back to main page compare notification that popInitialNotification return again with this global variable.
@Dallas62 thanks a lot for your answering.
Hi,
I think this is a problem with the configuration of react-native, like http
instead of https.
Regards,
Le sam. 18 avr. 2020 Ã 10:02, samaneh-kamalian notifications@github.com a
écrit :
Excuse me.I have problem in connecting to my server.
in debug mode I do not have problem but in release mode, app can not
connect to server!
can manifest.xml changes effect on app connection ?<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver>—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/zo0r/react-native-push-notification/issues/1367#issuecomment-615719339,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AA2FHULUZKBLDBOGWNTIQALRNFNB3ANCNFSM4MIO2CVA
.
clearAllLocalNotification remove all scheduled notifications then clear the notification center, but it doesn’t aim to remove initial notification.
Initial notification is not a pending scheduled notification and is not related to the notification center (not the same thing/goal)
how can we clear the all notification from popInitialNotification?
Thanks,
Most helpful comment
I think you can try without this part: