Describe your issue here
Background notifications not working on iOS. It has always been working, but I don't what happened now. Also, when I open the app after being in background or killed, any notifications sent while in background or killed gets received. I tried sending notification from firebase console, but also not being received in background, even more weird is that when it is displayed in foreground only sound or vibration happens, no notification pop up is displayed.
Click To Expand
#### `package.json`:
{
"name": "AppName",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@dudigital/react-native-zoomable-view": "^1.0.15",
"@react-native-community/async-storage": "^1.5.0",
"@react-native-community/cameraroll": "^1.3.0",
"@react-native-community/netinfo": "^5.0.1",
"@terrylinla/react-native-sketch-canvas": "^0.8.0",
"axios": "^0.19.0",
"lodash": "^4.17.15",
"react": "^16.12.0",
"react-native": "^0.61.5",
"react-native-af-video-player": "^0.2.1",
"react-native-animatable": "^1.3.3",
"react-native-animated-linear-gradient": "^1.2.0",
"react-native-audio": "^4.3.0",
"react-native-cached-image": "^1.4.3",
"react-native-camera": "^3.15.0",
"react-native-collapsible": "^1.5.1",
"react-native-confirmation-code-input": "^1.0.4",
"react-native-datepicker": "^1.7.2",
"react-native-device-info": "^2.1.2",
"react-native-fast-image": "^7.0.2",
"react-native-fetch-blob": "^0.10.8",
"react-native-firebase": "^5.6.0",
"react-native-fs": "^2.16.2",
"react-native-gallery-manager": "^1.0.9",
"react-native-gesture-handler": "^1.5.2",
"react-native-gifted-chat": "^0.7.3",
"react-native-google-places-autocomplete": "^1.4.0",
"react-native-image-pan-zoom": "^2.1.11",
"react-native-image-resizer": "^1.1.0",
"react-native-interactions": "^0.4.0",
"react-native-iphone-x-helper": "^1.2.1",
"react-native-keep-awake": "^4.0.0",
"react-native-keyboard-aware-scroll-view": "^0.9.1",
"react-native-keychain": "^4.0.4",
"react-native-linear-gradient": "^2.5.6",
"react-native-mime-types": "^2.2.1",
"react-native-modal": "^11.5.3",
"react-native-navigation-bar-color": "^1.0.0",
"react-native-orientation": "^3.1.3",
"react-native-permissions": "^2.0.8",
"react-native-rate": "^1.1.10",
"react-native-reanimated": "^1.4.0",
"react-native-responsive-screen": "^1.3.0",
"react-native-scalable-image": "^1.0.0",
"react-native-screens": "^2.0.0-alpha.22",
"react-native-shadow": "^1.2.2",
"react-native-share": "^2.0.0",
"react-native-smooth-pincode-input": "^1.0.9",
"react-native-sound": "^0.11.0",
"react-native-splash-screen": "^3.2.0",
"react-native-store-photos-album": "^0.1.2",
"react-native-svg": "^9.13.6",
"react-native-swift": "^1.2.2",
"react-native-thumbnail": "^1.1.3",
"react-native-vector-icons": "^6.5.0",
"react-native-video": "^5.0.2",
"react-native-video-cache": "^1.0.0",
"react-native-webview": "^8.0.1",
"react-native-youtube": "^2.0.0",
"react-navigation": "^4.0.10",
"react-navigation-collapsible": "^3.0.3",
"react-navigation-stack": "^1.10.3",
"react-navigation-tabs": "^2.6.2",
"react-navigation-transitions": "^1.0.12",
"react-redux": "^7.1.3",
"redux": "^4.0.4",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.7.7",
"@babel/runtime": "^7.7.7",
"babel-jest": "^24.9.0",
"jest": "^24.9.0",
"jetifier": "^1.6.5",
"metro-react-native-babel-preset": "^0.54.1",
"react-test-renderer": "^16.12.0"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"./assets/fonts"
]
},
"isSwift": true
}
#### `firebase.json` for react-native-firebase v6:
# N/A
### iOS
#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
target 'AppName' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
# use_frameworks!
# use_modular_headers!
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/'
pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec', :modular_headers => false
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec', :modular_headers => false
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec', :modular_headers => false
pod 'Firebase/Core'
pod 'Firebase/Analytics'
pod 'Firebase/Auth'
pod 'Firebase/Messaging'
pod 'Firebase/Database'
permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone.podspec"
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary.podspec"
target 'BroadcastExtension' do
pod 'SimpleKeychain',:modular_headers => true
pod 'SwiftyJSON'
pod 'Alamofire'
pod 'SDWebImage',:modular_headers => true
end
target 'AppNameTests' do
inherit! :search_paths
# Pods for testing
end
use_native_modules!
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
end
#### `AppDelegate.m`:
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
#import "RNSplashScreen.h"
#import <os/log.h>
#import <React/RCTLinkingManager.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[RNFirebaseNotifications configure];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"AppName"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[RNSplashScreen show];
return YES;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}
@end
Click To Expand
#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`:
// N/A
#### `android/app/build.gradle`:
// N/A
#### `android/settings.gradle`:
// N/A
#### `MainApplication.java`:
// N/A
#### `AndroidManifest.xml`:
<!-- N/A -->
Click To Expand
**`react-native info` output:**
System:
OS: macOS 10.15.2
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Memory: 266.47 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.16.0 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 23, 25, 26, 27, 28
Build Tools: 26.0.2, 26.0.3, 27.0.3, 28.0.2, 28.0.3
System Images: android-27 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 11.3/11C29 - /usr/bin/xcodebuild
npmPackages:
react: ^16.12.0 => 16.12.0
react-native: ^0.61.5 => 0.61.5
npmGlobalPackages:
react-native-cli: 2.0.1
- **Platform that you're experiencing the issue on**:
- [x ] iOS
- [ ] Android
- [ ] **iOS** but have not tested behavior on Android
- [ ] **Android** but have not tested behavior on iOS
- [ ] Both
- **`react-native-firebase` version you're using that has this issue:**
- `5.6.0`
- **`Firebase` module(s) you're using that has the issue:**
- `Notifications`
- **Are you using `TypeScript`?**
- `N`
Think react-native-firebase
is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]
React Native Firebase
and Invertase
on Twitter for updates on the library.You don't specify the iOS Firebase SDK pod versions in your Podfile, recommended to specify and use 6.14.0 (current)
This might just be a matter of iOS power-saving you though. For the best chance of receiving background messages you have to do a lot of things that "educate" the power-saving logic that the user wants the app to get a power allocation. This includes using the app, having a lot of power available (full battery, plugged in, not in low-power mode) etc. I notice highly variable delivery stats between different users on the same app version / same iOS version / same phone model myself.
@mikehardy I am using 6.14.0. The phone is 100% charged, connected to a power source, and not in lower-power mode, silent or any of that. However, to my surprise it is now working ... I have no idea why it was not working, and why now it is working ... and for how long will it be working.
Probably something to do with token rotation / stale tokens in FCM etc contributing to it being indeterminate like this
Any update about this issue?
I'm facing the same problem. In my case, on iOS when notification arrive, it trigger firebase.messeging().onMessage()
method instead of firebase.notification.onNotification()
.
I also tried Firebase/Messaging 6.14.0 on my Podfile
But on Android, it works fine both foreground and background and it calls firebase.notification.onNotification()
method.
@prayuditb i have the same issue, have u solved it?
I tested a bunch and found this issue. I'm having the same problems.
@7laria I'm still facing this issue
Having same issue with react-native-firebase
6.3.0
Having the same issue.. has anyone found a solution or a workaround?
Having same issue too on iOS. Only trigger firebase.messaging().onMessage
react-native-firebase 5.6.0
Or maybe I just be blocked by APNs?
And it can also explains why my firebase_admin server got success from firebase and really get message but no notification
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
....
[FIRApp configure];
[RNFirebaseNotifications configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
[application registerForRemoteNotifications];
return YES;
}
...
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}
...
PushNotificationController.js
import React, { Component } from "react";
import { StyleSheet, Platform, Image, Text, View, ScrollView ,Alert} from 'react-native';
import firebase from 'react-native-firebase';
import AsyncStorage from '@react-native-community/async-storage';
export default class PushNotificationController extends Component {
constructor(props) {
super(props);
}
async componentDidMount() {
this.checkPermission();
this.createNotificationListeners();
}
async checkPermission() {
const enabled = await firebase.messaging().hasPermission();
if (enabled) {
this.getToken();
} else {
this.requestPermission();
}
}
async getToken() {
let fcmToken = await AsyncStorage.getItem('fcmToken');
if (!fcmToken) {
fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
// user has a device token
await AsyncStorage.setItem('fcmToken', fcmToken);
}
}
console.log('fcmToken', fcmToken)
}
async requestPermission() {
try {
await firebase.messaging().requestPermission();
// User has authorised
if (!firebase.messaging().isRegisteredForRemoteNotifications) {
await firebase.messaging().registerForRemoteNotifications();
}
this.getToken();
} catch (error) {
// User has rejected permissions
console.log('permission rejected');
}
}
//Remove listeners allocated in createNotificationListeners()
componentWillUnmount() {
this.notificationListener();
this.notificationOpenedListener();
this.notificationDisplayedListener()
}
async createNotificationListeners() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
const { title, body } = notification;
console.log("firebase.messaging().onNotificationDisplayed")
this.showAlert(title, body);
});
/*
* Triggered when a particular notification has been received in foreground
* */
this.notificationListener = firebase.notifications().onNotification((notification) => {
const { title, body } = notification;
console.log("firebase.notifications().onNotification")
this.showAlert(title, body);
});
/*
* If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
* */
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
const { title, body } = notificationOpen.notification;
console.log("firebase.notifications().onNotificationOpened")
this.showAlert(title, body);
});
/*
* 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 } = notificationOpen.notification;
console.log("firebase.notifications().getInitialNotification")
this.showAlert(title, body);
}
/*
* Triggered for data only payload in foreground
* */
this.messageListener = firebase.messaging().onMessage((message) => {
//process data message
console.log("firebase.messaging().onMessage", JSON.stringify(message));
});
}
showAlert(title, body) {
Alert.alert(
title, body,
[
{ text: 'OK', onPress: () => console.log('OK Pressed') },
],
{ cancelable: false },
);
}
render() {
return null;
}
}
Having the same issue..
Having same issue too on iOS. Only trigger
firebase.messaging().onMessage
...
It runs perfectly on Android 8.0.
implementation "com.google.android.gms:play-services-base:16.0.1"
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
Maybe this issue only occurred on iOS.
I'm new on apps developing.
If you need more information about it, please feel free to let me know.
I've fixed this issue on my end. I realize when I trigger firebase.messaging().ios.getAPNSToken()
, I got null.
And this solution works for me
I added these line on Info.plist
:
<key>FirebaseAppDelegateProxyEnabled</key>
<string>NO</string>
edit AppDelegate.h
and change this line
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
become:
@import UserNotifications;
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
Also, in AppDelegate.m
```
// .... react native code related ....
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
[application registerForRemoteNotifications];
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; [RNFirebaseNotifications configure]; // .... react native code related .... [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; [application registerForRemoteNotifications]; return YES; }
What goes exactly in the ...react native code related... ??
@AyoubXwire I mean it just root view and bridge stuff.
I have fixed this issue.
After few days, I have decided to start over my react-native-firebase setup. I found this very helpful and well explained tutorial
"react-native-firebase": "5.5.6"
platform :ios, '9.0'
target 'FordDev' do
pod 'Firebase/Messaging', '~> 6.2.0' <-- add this line
target 'FordDevTests' do
inherit! :search_paths
# Pods for testing
end
use_native_modules!
end
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// custom
[FIRApp configure];
[RNFirebaseNotifications configure];
...
return YES;
}
// custom
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}
it now works like magic 馃殌
thanks @helenaford
@prayuditb , @DevPolo not working in react-native-firebase 6.3.0
Hey guys, thank you for your efforts and comments, I wanted to ask a question regarding Firebase Cloud Messaging of React-Native-Firebase 6.x
I saw in the docs that setBackgroundMessageHandler
is Android Only, and my question is,
Is there any way to handle Messages in the background but for iOS ?
I'm receiving FCM Data messages only and wanted to trigger a local notification with other lib, it works as expected in Android but for iOS I couldn't find a way to do this.
@prayuditb Hi. I got same issue with ios in background. I am using firebase v5, Can you share your request payload and code in AppDelegate.m, I mean are there anymore code needed after didFinishLaunchingWithOptions?
I've fixed this issue on my end. I realize when I trigger
firebase.messaging().ios.getAPNSToken()
, I got null.And this solution works for me
I added these line on
Info.plist
:<key>FirebaseAppDelegateProxyEnabled</key> <string>NO</string>
edit
AppDelegate.h
and change this line@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
become:
@import UserNotifications; @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
Also, in
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; [RNFirebaseNotifications configure]; // .... react native code related .... [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; [application registerForRemoteNotifications]; return YES; }
This fix from @AyoubXwire solved our issue!!
Hey all 馃憢 There's a draft PR available which fixes this issue and others, please check it out: https://github.com/invertase/react-native-firebase/pull/3339
We'll be doing a RC release once a few more things are implemented.
https://github.com/invertase/react-native-firebase/issues/3069#issuecomment-586126431
Worked for me!
@prayuditb which is your version of @react-native-firebase/messaging ?
I am using 6.7.1 and there is no way to get background messages to work in iOS.
May your changes could be applied to master branch since it appears to be a bug and It still in the last release.
With current stable versions of everything I have iOS background messages working just fine. The module works.
Make sure you send the content-available APNS item as documented everywhere or you will not receive them
version information (TL;DR: no that's stale): https://rnfirebase.io/releases
related docs for getting it to work: https://rnfirebase.io/messaging/usage#data-only-messages
Thks @mikehardy, I have missed the content-available APNS step for iOS. I just added and it's start to work in background too.
Seizing the opportunity, after the APNs were changed from certificate APNs to key authentication APNs, it's no longer needed to update the certificates. My question is: nothing more will be needed to refresh?
With all things messaging-related and especially on iOS - the answer is pretty much "test it then test it again" - you have to answer your own question in other words because this stuff is so finicky. And by "test it" that's with a real device plugged in and watching Xcode logs. For your specific question, I'm not sure? If you received your data only message while the app was in not foreground and not force quit (so should be background state), that should be it.
That was a pretty good advice. I appreciate you help, thks so much. We gonna do it!
Today I have discovered that sending content_available: true have worked in iOS 12.x but not in 13.x.
I have found this answer, seems apple have changed the way background processing is made.
https://stackoverflow.com/questions/57197958/xcode-11-what-is-the-new-background-processing-background-mode/58101161#58101161
If this answer is right an extra step in AppDelegate.m, method ApplicationDidFinishLaunchingWithOptions will be necessary.
@mikehardy did you notice if iOS 13 really need it ?
On current versions, setting content available works for me on ios13, no app delegate extras
@mikehardy, for our records today I have tested in real device with ios13 it's work as well. There is an issue with ios13 emulator. My xcode is v11.3 that's the reason of my delay, therefore I depend on apple test flight and It's not practical like usb deploy. As you have said, these things must to be tested in multiples scenarios.
I have simplify push send using CURL
curl -H "Content-type: application/json" -H "Authorization:key=#MyAuthHashCode#" -X POST -d '{ "to": "/topics/#thetopicnumber#","notification": { "title": "msg for topic", "body": "bodytext", "content_available": "true" }}' https://fcm.googleapis.com/fcm/send
I appreciated your help, thks!
@mikehardy I have tested my application in background, foreground, and kill state the notifications are not getting triggered. But when the app is in foreground , onMessage is getting triggered.
My code is as below
`- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// [FIRApp configure];
// [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
// [START configure_firebase]
[FIRApp configure];
// [END configure_firebase]
// [START set_messaging_delegate]
[FIRMessaging messaging].delegate = self;
// [END set_messaging_delegate]
[RNFirebaseNotifications configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
[application registerForRemoteNotifications];
return YES;
// [START receive_message]
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print message ID.
if (userInfo[kGCMMessageIDKey]) {
NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
}
// Print full message.
NSLog(@"%@", userInfo);
}
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print message ID.
if (userInfo[kGCMMessageIDKey]) {
NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
}
// Print full message.
NSLog(@"%@", userInfo);
completionHandler(UIBackgroundFetchResultNewData);
}
// [END receive_message]
// [START ios_10_message_handling]
// Receive displayed notifications for iOS 10 devices.
// Handle incoming notification messages while app is in the foreground.
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print message ID.
if (userInfo[kGCMMessageIDKey]) {
NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
}
// Print full message.
NSLog(@"%@", userInfo);
// Change this to your preferred presentation option
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
}
// Handle notification messages after display notification is tapped by the user.
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print full message.
NSLog(@"%@", userInfo);
completionHandler();
}
// [END ios_10_message_handling]
// [START refresh_token]
// This function is added here only for debugging purposes, and can be removed if swizzling is enabled.
// If swizzling is disabled then this function must be implemented so that the APNs device token can be paired to
// the FCM registration token.
// With swizzling disabled you must set the APNs device token here.
// [FIRMessaging messaging].APNSToken = deviceToken;
}
`
pod 'Firebase/Messaging', '~> 6.2.0' <-- add this line
@DevPolo thanku so much.
Sol:-
pod 'Firebase/Messaging', '~> 6.2.0' <-- add this line
Most helpful comment
I've fixed this issue on my end. I realize when I trigger
firebase.messaging().ios.getAPNSToken()
, I got null.And this solution works for me
I added these line on
Info.plist
:edit
AppDelegate.h
and change this linebecome:
Also, in
AppDelegate.m
```
{
[FIRApp configure];
[RNFirebaseNotifications configure];
// .... react native code related ....
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
[application registerForRemoteNotifications];
return YES;
}