FCM notification not working when app is kill/closed

which plugin use FCM or Push?

In push plugin click action is not working.

Can anyone find any solution?

@nirav_ionic thank you so much finally i found the solution using https://ionicframework.com/docs/native/push/.

always welcome

please mark as solution so easily identified by other

Just need to implement forceStart:“1” in JSON format and app will be awake from closed app so finally this is my final code with REST API

<===== REST API =====>

 let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('Authorization', 'key=' + "**SERVER KEY**");
    let option = new RequestOptions({ headers: headers });
    let body = {
      "data": {
        "title": "TITLE",
        "body": "MSG",
        "forceStart": "1"
      },
      "priority": "high",
      "to": **TOKEN**
    }
    this.http.post('https://fcm.googleapis.com/fcm/send', JSON.stringify(body), option)
      .map(res => res.json())
      .subscribe(data => {
        console.log(data);
        this.autostart.enable();
      });
  }
<===== PusH plugin ====>
const options: PushOptions = {
			android: {
				senderID: '**APP ID**',
				sound: 'true',
				vibrate: true,
				forceShow: "1",
			},
			ios: {
				alert: 'true',
				badge: 'true',
				sound: 'true',
				clearBadge: 'true'
			},
			windows: {}
		};
		const pushObject: PushObject = this.push.init(options);

		pushObject.on('notification').subscribe((notification: any) => {**foreground and background coding**});
		pushObject.on('registration').subscribe((data: any) => {
			console.log('device token -> ' + data.registrationId);			
		});
		pushObject.on('error').subscribe(error => console.error('Error with Push plugin' + error));


	}
5 Likes

Hi Muji,
Could you explain how do you do with OneSignal to send/receive notifications when app is closed/killed ?

You don’t do anything special.
Notifications are received by default when app is closed.

Not for me … I can receive notifications when app in foreground or background but not when the app is closed…

Is that for Android or iOS?

Android, thanks if you can help me

Not really sure. It requires a bit of analysis.
Have you checked the OneSignal console? It should have details of each message sent.

Also check if the app is still running from your “app settings” if the “stop all” button is not enabled then the app is fully killed and it won’t receive a notification.
This is the case with all apps, you can try force stop WhatsApp from there and you would see that you don’t receive a notification

Thanks ! I think the issue is that my app isn’t running anymore when I close it… I don’t know exactly how to let it run, but I will try to use the plugin autostart which could help me to run a service of the in background.

Hi, you shouldn’t need autostart, your phone is probably optimising performance by killing some apps.
Check ur phone settings and any optimising apps you might have installed

1 Like

Hi! @Muji , I have the same problem in Android :frowning:
With OneSignal It’s works fine in iOS, but when I close my app in Android push notification don’t receive anymre

hi @jbgomez21, have you seen my above solution code and have you try it ?

Hi @Anithakor0610, I don’t understand where do you have to implement your “REST API” code … Do you think your solution works with OneSignal ?

hi @Favral this solution works fine with Push notification plugin and REST API you can check this REST API in postman then Apply your API in send message function.

Hi Anitha,

I have tested from postman but unable to send the notification when app is closed.
Please help me striggling with this issue from 15 days

@Anithakor0610 sending the notification from the postman but unable to receiving the device. what i am doing wrong here.

Please help me.