evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 681 forks source link

Failed to post notification on channel "null" #1048

Open rjsajnani1 opened 5 years ago

rjsajnani1 commented 5 years ago

Getting this issue from Android 8 and above. The notifications works fine on iOS upto iOS 12 and below Android 8.

  1. RN :0.51.0 and react FCM: 16.2.3
  2. Android 8 pixel simulator
  3. Foreground screen shot 2018-09-24 at 3 10 38 pm 1
christianchown commented 5 years ago

I found that notifications stopped working for me after I upgraded my phone to Android 8.0

Passing a channel (string) through as part of the custom_notification block made my notifications work again.

(It uses it here:)

https://github.com/evollu/react-native-fcm/blob/b587872fadff2bb989fd8c9ac8bd1046e345498c/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java#L81

rjsajnani1 commented 5 years ago

@christianchown thanks for your help will try out the solution.

rjsajnani1 commented 5 years ago

@christianchown i did try it out but still was getting the same error. I can see the channel in my notifications but when ever i pass a notification from FCM or server with the same channel id. I still get the same error.

Can u provide me a example of your code so i can try to see how it looks. I dont use any custom notifications. I have also added <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="default"/> in my AndroidMainfest.xml

await FCM.createNotificationChannel({ id: 'default', name: 'Default', description: 'general usage', priority: 'high' }) before my registerAppListener as well.

christianchown commented 5 years ago

I just noticed I don't have a default_notification_channel_id - I should probably add one. I've also set up my project for local notifications as specified in https://github.com/evollu/react-native-fcm#android

I send notifications differently depending on whether the platform is Android or iOS:

function getPayload(platform, title, body, extraData = null, badge = 0) => {
  const payload = {};
  if (platform === 'android') {
    const large_icon = // url
    const color = // #RGB
    const channel = // channel ID
    payload.data = {
      custom_notification: JSON.stringify({
        title,
        body,
        priority: 'high',
        sound: 'default',
        click_action: 'ACTION',
        large_icon,
        big_text: body,
        icon: 'ic_notif',
        color,
        show_in_foreground: true,
        badge: badge.toString(),
        channel,
        ...(extraData || {}),
      }),
    };
  } else {
    payload.notification = {
      title,
      body,
      badge: badge.toString(),
    };
    if (extraData) payload.data = extraData;
  }
  return payload;
};

const payload = getPayload(platform, title, body, extraData, badge);
const response = await firebase.messaging().sendToDevice(token, payload);
stsiushkevich commented 5 years ago

I have the same issue when my App is in the background. Can anyone help us?

DV31 commented 5 years ago

once you create a notification channel this issue will fix.

wmonecke commented 5 years ago

createNotificationChannel is undefined on my FCM object.

I can NOT do

FCM.createNotificationChannel({ id: 'default', name: 'Default', description: 'general usage', priority: 'high' })

Do I need to upgrade??

yusuf987 commented 5 years ago

hi @christianchown

am I missing something?

i have tried adding below as described NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext, bundle.getString("channel"))

i also add below in manifest

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="default"/>

and i am hitting notification from postman as below image

now its shows below error instead of channel "null" its showing channel id am passing from payload image

rjsajnani1 commented 5 years ago

We switched to using react-native-fcm that solved this problem for us