Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android did not receive any notification, but IOS working properly #1380

Closed
kurroo10 opened this issue Apr 23, 2020 · 23 comments
Closed

Android did not receive any notification, but IOS working properly #1380

kurroo10 opened this issue Apr 23, 2020 · 23 comments
Labels

Comments

@kurroo10
Copy link

kurroo10 commented Apr 23, 2020

Question

this is wierd actually, a day ago on Android , the push notification is working even when application is on Foreground or Background. then im going for implement it on IOS, its working too even in Debug or Release.

but, when i try to test on Android again, look like it got some problem. it's working if im test using Firebase Console by targeting Device Token Directly, but when i try to Target to App like bellow, its now not working, same as if im close the application.

Working :
image

Not Working :
image

i have test it send to both Ios and Android, the the result is IOS got the push notification, but Android is NOT.

Here's the code i have using on my React Native code :

async componentDidMount(){
      this.pushNotificationListener();
    }

    pushNotificationListener = async () => {
           //Handling like this because on IOS, onNotification not Fired, and i ended doing something dirty like so, sad but working
       messaging().onMessage((payload) => {
         console.log('[payload] : ',payload)
         this.showNotification(payload)
      });
      PushNotification.configure({
        // (optional) Called when Token is generated (iOS and Android)
        onRegister:  (token) => {
          console.log("TOKEN:", token);
        },
        // (required) Called when a remote or local notification is opened or received
        onNotification:  (notification) => {
          console.log("NOTIFICATION:", notification);
          // process the notification
          this.showNotification(notification)
          // required on iOS only (see fetchCompletionHandler docs: https://github.com/react-native-community/react-native-push-notification-ios)
          notification.finish(PushNotificationIOS.FetchResult.NoData);
        },
        // ANDROID ONLY: FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications)
        senderID: "Some Sender ID",
        // IOS ONLY (optional): default: all - Permissions to register.
        permissions: {
          alert: true,
          badge: true,
          sound: true,
        }
      });
    }

    showNotification = (payload) => {
     //Handling like this because on IOS, onNotification not Fired, and i ended doing something dirty like so, sad but working
      let notification = {
        title : Platform.OS === 'ios' ? payload.notification.title : payload.title,
        message : Platform.OS === 'ios' ? payload.notification.body : payload.message
      };

      PushNotification.localNotification({
        largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
        smallIcon: "ic_launcher", // (optional) default: "ic_notification" with fallback for "ic_launcher"
        bigText: notification.message, // (optional) default: "message" prop
        vibrate: true,
        priority: "max",
        allowWhileIdle: true,

        title: notification.title, // (optional)
        message: notification.message, // (required)
      });
    }

Package.json :

    "react-native-push-notification": "^3.1.9",
    "@react-native-community/push-notification-ios": "^1.1.1",
    "@react-native-firebase/app": "6.4.1.alpha0",
    "@react-native-firebase/messaging": "6.4.1.alpha0",

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.testapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <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="com.testapp.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.testapp.permission.C2D_MESSAGE" />
    <!-- < Only if you're using GCM or localNotificationSchedule() > -->

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
      android:usesCleartextTraffic="true"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        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" />
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                android:value="YOUR NOTIFICATION CHANNEL NAME"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                    android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
        <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->

        <!-- < Only if you're using GCM or localNotificationSchedule() > -->
        <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="com.testapp" />
            </intent-filter>
        </receiver>
        <!-- < Only if you're using GCM or localNotificationSchedule() > -->

        <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"/>

        <!-- < Only if you're using GCM or localNotificationSchedule() > -->
        <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>
        <!-- </ Only if you're using GCM or localNotificationSchedule() > -->

        <!-- < Else > -->
        <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    </application>

</manifest>


@Dallas62
Copy link
Collaborator

Hi @bobbyrinaldy
Thanks for the report, I think it's fixed on master , can you test it ?

@Dallas62
Copy link
Collaborator

And I just saw you manifest is not up to date; check the Readme 😉

@kurroo10
Copy link
Author

kurroo10 commented Apr 23, 2020

Hi @bobbyrinaldy
Thanks for the report, I think it's fixed on master , can you test it ?

2 question :

  1. How about this line ? onNotification not fired on IOS 13.4, but messaging().onMessage did that
     //Handling like this because on IOS, onNotification not Fired, and i ended doing something dirty like so, sad but working
       messaging().onMessage((payload) => {
         console.log('[payload] : ',payload)
         this.showNotification(payload)
      });
  1. How can i pull the master branch to my project ? sorry for asking, im new on this one, i just know change version not directly to the package branch
    (Edit : nevermind, i can do like this 'react-native-push-notification' : zo0r/react-native-push-notification#master on package.json)

@kurroo10
Copy link
Author

kurroo10 commented Apr 23, 2020

Hi @bobbyrinaldy
Thanks for the report, I think it's fixed on master , can you test it ?

Quick Update :

  1. im updating the package to
    "react-native-push-notification": "zo0r/react-native-push-notification#master"

  2. update the manifest like so :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.testapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
      android:usesCleartextTraffic="true"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        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" />
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                android:value="YOUR NOTIFICATION CHANNEL NAME"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                    android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
        <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->

        <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>
    </application>

</manifest>

and result is the same as what im asking above, sorry.
@Dallas62

@Dallas62
Copy link
Collaborator

@bobbyrinaldy I will investigate ASAP

@kurroo10
Copy link
Author

kurroo10 commented Apr 23, 2020

@bobbyrinaldy I will investigate ASAP

okay, i will waiting for it then.

btw, thanks for your quick response, love what you did 👍

@Dallas62
Copy link
Collaborator

Hi @bobbyrinaldy
Do you need local notification or scheduled notification ?
If not, I think rnfirebase-messaging is enough for your case.

What I don't understand with this Firebase Feature is we just need to generate a token and setup analytics, but it's not enough... I saw you can send the token to a backend en register to a Topic (like android), and with rnfirebase: messaging().subscribeToTopic('weather')
rnfirebase#topics

@kurroo10
Copy link
Author

Hi @bobbyrinaldy
Do you need local notification or scheduled notification ?
If not, I think rnfirebase-messaging is enough for your case.

What I don't understand with this Firebase Feature is we just need to generate a token and setup analytics, but it's not enough... I saw you can send the token to a backend en register to a Topic (like android), and with rnfirebase: messaging().subscribeToTopic('weather')
rnfirebase#topics

push notification from rnfirebase-messaging cannot push the notification for me, idk why. but this package do

ya i know, but simple one is using this package to manage how FCM received like on IOS did.
so no other way to fix this ?

@kurroo10
Copy link
Author

kurroo10 commented Apr 26, 2020

Hi @Dallas62 ,
i have a question, If im using this package as Push Notification , should i install this one earlier or NOT NEDDED at all ?

  1. @react-native-firebase/app
  2. @react-native-firebase/messanging

i think my problem coming from i installed all of that RNFB

@Dallas62
Copy link
Collaborator

I don't know why rnfirebase is not working for you, or if there is any conflict, it's strange.
Maybe you should try to remove rnfirebase from AndroidManifest to test, or retry rnfirebase 😕

@kurroo10
Copy link
Author

I don't know why rnfirebase is not working for you, or if there is any conflict, it's strange.
Maybe you should try to remove rnfirebase from AndroidManifest to test, or retry rnfirebase 😕

yea thanks, try to to test push notification using CURL/Postman and it is seem's working now for Android to receive Notification on Foreground and Backround app, but still Dead/Killed state did not received. can you check it ?

@Dallas62
Copy link
Collaborator

For Dead/Killed, test with then version on master, the default channel is not created on the current version.

@kurroo10
Copy link
Author

kurroo10 commented Apr 26, 2020

For Dead/Killed, test with then version on master, the default channel is not created on the current version.

yes, im using like this on my package json :

"react-native-push-notification": "zo0r/react-native-push-notification#master"

and my Manifest like on Docs

<uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application ....>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                android:value="PUSH_NOTIFICATION"/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                    android:value="PUSH_NOTIFICATION"/>
        <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->

        <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>

@kurroo10
Copy link
Author

@Dallas62 i tried to build the apps on my other phone, seem's like onRegister called but when i hit with Postman , it say NotRegistered

image

image

@Dallas62
Copy link
Collaborator

I did the same test:
Capture d’écran 2020-04-26 à 12 20 02

@programmer-RN
Copy link

Hi, my iOS not working in foreground, but background is working, am I missing any setup?

"@react-native-firebase/app": "^6.4.0",
"@react-native-firebase/messaging": "^6.4.0",

@Dallas62
Copy link
Collaborator

Hi @programmer-RN
This issue is not related on iOS, you should look at :
react-native-push-notification/ios#106
react-native-push-notification/ios#107
Thanks

@Gabsys
Copy link

Gabsys commented May 4, 2020

Hi, my iOS not working in foreground, but background is working, am I missing any setup?

"@react-native-firebase/app": "^6.4.0",
"@react-native-firebase/messaging": "^6.4.0",

Why is mine behaving differently compared to all of you lmao. My android is working fine, my iOS foreground is working fine but iOS background can't work haha

@Dallas62
Copy link
Collaborator

Dallas62 commented May 4, 2020

hi @Gabsys, you can check others issues, this is due to a change in https://github.com/react-native-community/push-notification-ios

@Gabsys
Copy link

Gabsys commented May 4, 2020

hi @Gabsys, you can check others issues, this is due to a change in https://github.com/react-native-community/push-notification-ios

I can't find the relevant issues though. Could you give me some heads up/tips? ><

@Dallas62
Copy link
Collaborator

Dallas62 commented May 4, 2020

Try this one:
#1305 (comment)

@tanayuk
Copy link

tanayuk commented Jun 25, 2020

Originally this topic was to discuss Android remote push, right?
I'd like to know if someone could solve this...

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants