Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Notification not receiving in iOS for react native project

$
0
0

I have a react native project. I am able to receive the FCM token successfully but when trying to send a notification, the app doesn't receive the notification.
The steps I followed are as below:

  1. Created a project in Firebase Console.
  2. Added the Firebase .plist in the projectName through Xcode.
  3. ran npm install --save react-native-firebase
  4. Added in podfile: pod ‘Firebase/Core’
  5. ran pod install
  6. Update AppDelegate.m with #import <Firebase.h> and [FIRApp configure];
  7. Added the APNS in the Firebase Dashboard for iOS App Cloud Messaging.
  8. Updated the capabilities with Push Notification and Background Modes > Remote notification
  9. In info.plist FIRAnalyticsDebugEnabled, FirebaseAppDelegateProxyEnabled, FirebaseScreenReportingEnabled is set to No

using const fcmToken = await firebase.messaging().getToken(); I am able to get token.

Below is the code for the notification listener.

async createNotificationListeners() {    /*     * Triggered when a particular notification has been received in foreground     * */    this.notificationListener = firebase.notifications().onNotification((notification) => {        const {            title,            body        } = notification;        this.custom_data = notification.data;        const localNotification = new firebase.notifications.Notification({                show_in_foreground: true,            })            .setSound('default')            .setNotificationId(notification.notificationId)            .setTitle(notification.title)            .setBody(notification.body)        firebase.notifications()            .displayNotification(localNotification)            .catch(err => Alert.alert(err));    });    /*     * If your app is in foreground and background, you can listen for when a notification is clicked / tapped / opened as follows:     * */    this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {        if ("title" in notificationOpen.notification.data) {            const {                title,                body,                secret_key,                user_id,                realm_id,                user_os,                user_location            } = notificationOpen.notification.data;            this.props.navigation.navigate('Verify', {                title: title,                body: body,                secret_key: secret_key,                user_id: user_id,                realm_id: realm_id,                user_os: user_os,                user_location: user_location            });        } else {            const {                title,                body,                secret_key,                user_id,                realm_id,                user_os,                user_location            } = this.custom_data;            this.props.navigation.navigate('Verify', {                title: title,                body: body,                secret_key: secret_key,                user_id: user_id,                realm_id: realm_id,                user_os: user_os,                user_location: user_location            });        }    });    /*     * If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:     * */    const notificationOpen = await firebase.notifications().getInitialNotification();    if (notificationOpen) {        const {            title,            body,            secret_key,            user_id,            realm_id,            user_os,            user_location        } = notificationOpen.notification.data;        this.props.navigation.navigate('FCM', {            title: title,            body: body,            secret_key: secret_key,            user_id: user_id,            realm_id: realm_id,            user_os: user_os,            user_location: user_location        });    }    /*     * Triggered for data only payload in foreground     * */    this.messageListener = firebase.messaging().onMessage((message) => {        console.log("JSON.stringify:", JSON.stringify(message));    });}

Please do let me know if more details required.


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>