Grub
Grub

Reputation: 883

Unable to send push notifications from Firebase console using react-native-firebase

I am trying to send a push notification to my ios device from the Firebase console by token ID. I am using react-native-firebase to allow the app to perform actions based on the notification events. I followed the instructions to integrate the SDK and have set up the APNS certs etc:

http://invertase.io/react-native-firebase/#/installation-ios

My firebase.js config file looks like this:

import RNFirebase from 'react-native-firebase';

const configurationOptions = {
  debug: true
};

const firebase = RNFirebase.initializeApp(configurationOptions);

export default firebase;

My main React component looks like this:

import React, { Component } from 'react'
import {
  Text,
  View,
  Alert,
  Platform
} from 'react-native'
import firebase from './firebase'

export default class extends Component {

  constructor(props) {
     super(props)
     this.state = {
        token: ''
     }
  }

  componentDidMount() {
     firebase.messaging().getToken()
        .then((token) => {
           this.setState({ token })
           console.log('token: ', token)
        })

     firebase.messaging().getInitialNotification()
        .then((notification) => {
           console.log('Notification which opened the app: ', notification)
        })

     firebase.messaging().onMessage((message) => {
        console.log('messaging', message)
     })

     firebase.messaging().onTokenRefresh((token) => {
        console.log('Refreshed FCM token: ', token)
     })
  }

  render() {
     return (
        <View style={{ marginTop: 22 }}>
           <Text>{this.state.token}</Text>
        </View>
     )
  }

}

I successfully get the token when the component mounts and then use that in the Firebase console to send a notification, but the notification is not received. I am using a real device, not and iPhone. I am using a development provisioning profile with Push notifications enabled and the remove notifications back ground entitlement enabled successfully, along with the appropriate development APNs certificate, which has been uploaded to the firebase console.

Why am I not receiving the notification on the device?

Upvotes: 0

Views: 1409

Answers (1)

Grub
Grub

Reputation: 883

Okay, it looks like it was just ignoring the remote notifications because I had not requested permissions from the user. Just needed to do that via the SDK:

componentDidMount() {
    firebase.messaging().requestPermissions()
    firebase.messageing().getToken().then...

Upvotes: 2

Related Questions