everything is working fine when the app is in foreground/background. the notification is working and I
m getting the JSON. but when the app is killed or closed, nothing.
Here is AndroidManifest.xml:
`
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<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" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<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:windowSoftInputMode="adjustPan">
<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>
build.glade
dependencies {
...
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true`
same problem...
I have the same problem here, I only use the remote notification to handle when to show up a local notification. Everything works well until the application is closed. In this mode, the onNotification method is not called.
This is my manifest file:
`
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<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:launchMode="singleTask"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<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.RNPushNotificationListenerServiceGcm"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<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:launchMode="singleTask"
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>
`
Does anyone know what the problem is?
Same problem at me.
But maybe this is the expected behavior ...?
So its about 5 months from opening this issue and still no answer. Can someone provide solution? I mean this is really important issue. Without that the library is kind of useless. At least for me.
I had the same problem, but I figured in my case it was caused by popInitialNotification set to false in
PushNotification.configure, setting it to true solved it.
Did anyone get solution on this? I am facing the same problem :-(
Still facing this issue.
Same Issue here
Hi guys,
I managed to successfully send local notification when the app is closed (killed) using localNotificationSchedule().
This is my Notifications.js file :
import { AppState, PushNotificationIOS } from 'react-native';
import PushNotification from 'react-native-push-notification';
const _handleAppStateChange = nextAppState => {
if (nextAppState === 'active') {
_registerLocalNotification();
}
};
const _registerLocalNotification = () => {
PushNotification.setApplicationIconBadgeNumber(0);
PushNotification.cancelAllLocalNotifications();
const message = 'Ceci est un test';
//This is only for testing purpose, triggers a notification one minute after current time
const oldDate = new Date();
const date = new Date(oldDate.getTime() + 1*60000);
PushNotification.localNotificationSchedule({
/* Android Only Properties */
vibrate: true,
vibration: 300,
priority: 'high',
visibility: 'public',
importance: 'high',
/* iOS and Android properties */
message, // (required)
playSound: false,
number: 1,
actions: '["OK"]',
// Production timestamp
repeatType: 'day',
date: date
});
};
export default {
register: async () => {
PushNotification.configure({
onNotification: function(notification) {
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
popInitialNotification: true,
});
_registerLocalNotification();
AppState.addEventListener('change', _handleAppStateChange);
},
unregister: () => {
AppState.removeEventListener('change', _handleAppStateChange);
},
};
Then later in my App.js component :
useEffect(() => {
//....Previous code
Notifications.register();
return(() => {
Notifications.unregister();
})
});
Let me explain a little bit what happens here :
I'm using AppState to check when my app is active, when it's the case, I trigger my _registerLocalNotification function. In this function you can see that I'm cancelling all previous scheduled notifications first in order to prevent duplicates messages, then I register my notification.
In my main component I'm triggering my functions at mount and unmount (ComponentDidMount / ComponentWillUnmount classic React version if you prefer).
I tested it, and it successfully sends my notification 1 minute after I closed my app.
I was stuck 1 hour on that problem, I hope it will help some of you.
Hi,
This issue should be fixed on 3.3.1.
Most helpful comment
same problem...