React-native-fcm: Don't receive push notification when user kill app (Android & IOS)

Created on 5 Sep 2017  路  21Comments  路  Source: evollu/react-native-fcm

Hi @evollu,
My app can receive push notifcation on fourground and background. But app don't receive push notification when user kill app. Can you help me?

"react-native-fcm": "^9.1.0"
"react": "16.0.0-alpha.12"
"react-native": "^0.47.2",
Environment:
  OS:  macOS Sierra 10.12.5
  Node:  8.1.2
  Yarn:  0.24.6
  npm:  5.3.0
  Watchman:  4.7.0
  Xcode:  Xcode 8.3.3 Build version 8E3004b
  Android Studio:  2.3 AI-162.4069837

All 21 comments

what is your payload.
Have your enabled "background push" in xcode?

screen shot 2017-09-06 at 9 43 22 am

I have enabled "background push" in xcode.

Pay load:

{
"message": {"content": "testing 1"}
}

I don't understand why my app hasn't been notification when user kill app. @evollu

backend

const payload = {
    data: object,
    notification: {
      "sound": "default",
      "body" : object.content,
      "title" : object.title,
    }
  }

Now app can receive when user kill app, but app run foreground, app IOS receive 2 notifications when server push 1 time??? Can you help me? @evollu

Did you open the app by clicking the notification? In that case 2 notif is expected. There is a flag in notification that use can use to differ them.

How do you use to flag in notification (frontend or backend)? Can you write example code? @evollu

opened_from_tray is true if user tapped the banner

I was having this issue on android, adding sound: default in my notification payload from my server made it show up (and make a sound :D)

I have the same problem. In background or foreground i receive a push notification, but when app is killed i got nothing.

My Payload is:
{"notification": {"sound": "default", "title": "Some Title", "body": "message"}}

I guess i doing something wrong on the app side perhaps? Because i transform the push notification to a Local notification with:

this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
            if(notif.fcm != null && notif.fcm.body != null){
              FCM.presentLocalNotification({
                vibrate: 500,
                title: (notif.fcm != null && notif.fcm.title != null) ? notif.fcm.title : "Message",
                body:  notif.fcm.body,
                priority: "high",
                show_in_foreground: true,                         
                icon: "ic_launcher"
              });
            }

And I think that is not necessary right?

I'm using

"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-fcm": "7.5.1",

Hi,

The same, I Don't receive push notification when the app is killed. README say

// NOTE: if you want to handle notifications when app is closed, put another handler outside of component lifecycle because components won't be initialized.

A simple example please.

Thank you!!

Update guys, so is not related with the code, i managed to receive the push notification when i set my App to auto-start with the device.

I had to make this manually in my device (Zenfone 2) so, there is a way to request permission or force the auto-start of a React Native app?

@juvasquezg readme updated

@thoth-nexlesoft can this issue be closed now?

@jarbaspsf <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> should get the permission for you. unless your phone is some custom android system

@evollu i'm already using this permissions on android manifest, i followed the entire setup, adding the permission, services etc. But the app is not in the list to auto start with the device. The device has Android 6.0.1 installed. I will try in another device.

Anyway i need to force the auto start or at least, check if is possible to request to the user to make auto start happen. =/

https://inspiretech.zendesk.com/hc/en-us/articles/207046683-Why-can-t-I-receive-push-notification-I-m-using-Asus-Phone-or-Xiao-Mi-phone-

@jarbaspsf asus and xiaomi auto declines auto start permission.
someone mentioned a way to request it programmatically
https://stackoverflow.com/questions/39366231/how-to-check-miui-autostart-permission-programatically
you may find a way for asus as well.
once the method are confirmed I can update the repo to support those

I already follow that code on my xiaomi phone. What does it do is only show Autostart OS Settings and let user enable autostart on selected app, not enable autostart on selected app automatically.

Why some popular apps like FB and WhatsApp have autostart automatically? Does it do programmatically? No, these apps has been on whitelist by vendor (xiaomi, asus, etc). Other popular apps like Slack is not in whitelist, so user must enable manually.

AFAIK, the only option on this case is:

  1. Alert user to enable autostart on first install (if phone is xiaomi, asus, oneplus, etc)
  2. when click 'Okay', show autostart setting.

Currently, there is no way to check if my app is already on autostart or not programmatically.

And the bad news is: my app is crash when showing autostart programmatically on xiaomi (it show autostart setting, but my app immediately crash although it already on autostart or not) :(

checked some Chinese forums and looks like it is by design by like xiaomi, asus, oppo, Flyme etc for "better bootup speed and battery life". They provides their own whitelist activities.
more details might be found here https://github.com/ttdevs/KillMe

One simple solution might be adding a Toast to ask users to enable auto start themselves.

closing this as the original issue seems to be solved. feel free to reopen.

Any updates on how to take auto-start permission for phones like xiaomi, asus, etc. in react native ?
Or
How to list your app in white listed apps?

@akash-cp I'm not planning to support these phones because I don't haven't any of those. PRs are welcomed

How to list your app in white listed apps? not possible. the vendor decides who gets whitelisted.

I have same issue one plus mobile. @akash-cp any update on this??

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mts88 picture mts88  路  5Comments

Udbhav12 picture Udbhav12  路  4Comments

xavieramoros picture xavieramoros  路  4Comments

404sand808s picture 404sand808s  路  5Comments

Keksike picture Keksike  路  5Comments