Skip to content

Not receiving notifications when app is closed IOS #306

@darkcoderrises

Description

@darkcoderrises

I have an app which uses react-native-firebase. I followed the initialisation steps provided for installing the app and for cloud messaging. Now when I use firebase console to send notification to a single user (haven't tried sending to a bunch, but I guess result would be the same), I receive the notification if the app is open, otherwise not. I read somewhere that when app is closed, one doesn't receive notification in the code, rather user see's a notification in notification bar and when clicked on, it invokes getInitialNotification().

  1. Target Platform : iOS
  2. Development Operating System: macOS Sierra
  3. Build tools: Xcode 8.2.1
  4. React Native version 0.45.1
  5. RNFirebase Version 2.0.4

Podfile:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'FroogalMerchant' do
  pod "Yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'BatchedBridge', 
    'Core',
    'RCTText',
    'RCTWebSocket',
    'RCTNetwork',
  ]

  pod 'Firebase/Core'
  pod 'RNFirebase', :path => '../node_modules/react-native-firebase'  

  pod 'Firebase/Analytics'
  pod 'Firebase/Messaging'

  target 'FroogalMerchantTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

Notification Listener component

import React, {Component} from 'react'
import {View, Platform} from 'react-native'
import firebase from '../utils/Firebase.js'

export default class NotificationListener extends Component {
  componentWillMount() {
    firebase.messaging().onMessage((message) => console.log('message', message));
    // This gets logged only when the app is open
    // Nothing happens when app is closed, no notification is shown either


    firebase.messaging().getInitialNotification()
      .then((notification) => {
        console.log('Notification which opened the app: ', notification);
      });
    // This is never called
  }

  render() {
    return (
      <View style={{width: '100%', height: '100%'}}>
        {this.props.children}
      </View>
    );
  }
}

Notification I am sending:

{
"registration_ids" : [""],
"notification": {
"title" : "Hi",
"body" : "Heyy"
},
"priority": "high"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: messagingFCM only - ( messaging() ) - do not use for Notifications

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions