invertase / react-native-firebase

šŸ”„ A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.71k stars 2.22k forks source link

šŸ”„[šŸ›] iOS push not received but yes on android #5016

Closed nachocifu closed 3 years ago

nachocifu commented 3 years ago

Issue

Followed the steps to add cloud messaging to app. Was already running analytics OK so base app is installed correctly. Push notifications are working perfect for android but iOS are never received.

Regarding APN conf:

import { useEffect } from 'react'
import messaging from '@react-native-firebase/messaging'
import { FCM_TOPIC } from '../config/env'

export default () => {
    const requestUserPermission = async () => {
        const authStatus = await messaging().requestPermission()
        const enabled = (authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL)
        if(enabled) {
            console.tron('FCM: accepted permissions')
            messaging()
              .getToken()
              .then(token => {
                console.tron(`FCM: Token after permissions ${token}`)
              });
        }
        else
            console.tron('FCM: rejected permissions')
        return enabled
    }
    useEffect(() => {
        if (requestUserPermission()) {
            messaging().setBackgroundMessageHandler(async remoteMessage => {
                console.tron(
                    'FCM: Message handled in the background!',
                    remoteMessage,
                )
            })

            const unsubscribe = messaging().onMessage(async remoteMessage => {
                console.tron('FCM: onMessage triggered')
                console.tron('FCM: A new FCM message arrived!', { remoteMessage })
            })

            messaging()
                .subscribeToTopic(FCM_TOPIC)
                .then(() => {
                    console.tron(`FCM: Topic ${FCM_TOPIC} Suscribed`)
                })

            messaging()
              .getToken()
              .then(token => {
                console.tron(`FCM: Token ${token}`)
              });

            return unsubscribe
        }
    }, [])
}

Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "app", "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": { "@react-native-community/async-storage": "^1.12.1", "@react-native-community/checkbox": "^0.4.2", "@react-native-community/datetimepicker": "^3.0.6", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/toolbar-android": "0.1.0-rc.2", "@react-native-firebase/analytics": "^11.0.0", "@react-native-firebase/app": "^11.0.0", "@react-native-firebase/messaging": "^11.0.0", "axios": "^0.19.2", "moment": "^2.29.1", "react": "16.13.1", "react-native": "0.63.3", "react-native-camera": "^3.40.0", "react-native-document-picker": "^3.5.4", "react-native-elements": "^2.3.2", "react-native-flash-message": "^0.1.17", "react-native-gesture-handler": "^1.8.0", "react-native-modal": "^11.5.6", "react-native-picker-select": "^7.0.0", "react-native-reanimated": "^1.13.2", "react-native-safe-area-context": "^3.1.9", "react-native-screens": "^2.15.0", "react-native-splash-screen": "^3.2.0", "react-native-svg": "^12.1.0", "react-native-swiper": "^1.6.0", "react-native-table-component": "^1.2.1", "react-native-vector-icons": "^6.7.0", "react-navigation": "^4.4.3", "react-navigation-animated-switch": "^0.6.3", "react-navigation-drawer": "^2.6.0", "react-navigation-stack": "^2.10.2", "react-redux": "^7.2.2", "redux": "^4.0.5", "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", "redux-thunk": "^2.3.0", "validate.js": "^0.13.1" }, "devDependencies": { "@babel/core": "^7.12.7", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^0.0.5", "babel-jest": "^24.9.0", "eslint": "^6.5.1", "jest": "^24.9.0", "metro-react-native-babel-preset": "^0.58.0", "react-test-renderer": "16.11.0", "reactotron-react-native": "^4.0.3", "reactotron-redux": "^3.1.2" }, "jest": { "preset": "react-native" } } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '10.0' # Override Firebase SDK Version $FirebaseSDKVersion = '7.8.0' target 'app' do config = use_native_modules! use_react_native!(:path => config["reactNativePath"]) target 'appTests' do inherit! :complete # Pods for testing end # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable these next few lines. use_flipper!({ 'Flipper' => '0.74.0' }) post_install do |installer| flipper_post_install(installer) end end target 'app-tvOS' do # Pods for app-tvOS target 'app-tvOSTests' do inherit! :search_paths # Pods for testing end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import "RNFBMessagingModule.h" #import #import #import #import #import #ifdef FB_SONARKIT_ENABLED #import #import #import #import #import #import static void InitializeFlipper(UIApplication *application) { FlipperClient *client = [FlipperClient sharedClient]; SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client start]; } #endif @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([FIRApp defaultApp] == nil) { [FIRApp configure]; } #ifdef FB_SONARKIT_ENABLED InitializeFlipper(application); #endif NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions]; RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"app" initialProperties:appProperties]; 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 } @end ```


Android

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`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 11.2.2 CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz Memory: 462.35 MB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 12.20.0 - /usr/local/opt/node@12/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.8 - /usr/local/opt/node@12/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 3.5 AI-191.8026.42.35.5977832 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: react: 16.13.1 => 16.13.1 react-native: 0.63.3 => 0.63.3 npmGlobalPackages: react-native-rename: 2.4.1 react-native: 0.61.5 ``` - **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:** - 11.0.0 - **`Firebase` module(s) you're using that has the issue:** - Messaging

mikehardy commented 3 years ago

Hi there!

There is a matrix of types of JSON you can send (by the FCM REST API -> only use the FCM REST API while testing, so you can control the JSON) vs the handlers that will be triggered + when they will trigger

Please post your JSON (minus the device token) exactly as sent to FCM REST API

Please make sure you only test on a real device. It does not work on the simulator (this is documented)

Please make sure you watch the console output (from Xcode or Console.app) with -FIRDebugEnabled in your build so you can observe what is happening

Please make sure content-available header is set if you are doing data only push

Definitely search old issues, there is nothing unique about people having problems with FCM message delivery, it's all been covered before - it definitely works though, so the info is probably out there already.

gazedash commented 3 years ago

Same problem, but for me regular pushes do work, and data - don't iOS on Android both work fine

mikehardy commented 3 years ago

"Same problem" - in my experience with FCM no single person has the same problem. Everyone usually has about 3 problems (no exaggeration!) in some different combination from every other person.

They work though. Follow every document about 4 times. Do a tiny toy app that does nothing but FCM and use the FCM REST API in order to test different combos of react-native-firebase listener calls and JSON styles.

And follow all my "Please..." guidelines above.

gazedash commented 3 years ago

Make sure you have "Background app refresh" enabled on ios device - it was the case for me

mikehardy commented 3 years ago

I love that I get the thumbsdown, but my suggestions actually fix problems for people. :shrug: :laughing:

hlandao commented 3 years ago

We had an issue with getting the onMessage hook invoked on iOS 14.3, this was fixed on iOS 14.4.

Shahulul commented 3 years ago

Same here, sometimes it works sometimes not. Using SDK Firebase/Core (6.34.0):

mikehardy commented 3 years ago

@Shahulul your firebase-ios-sdk is woefully out of date https://rnfirebase.io/releases/ / https://firebase.google.com/support/release-notes/ios - get up to date on react-native-firebase and firebase-ios-sdk. That said, iOS silent / data-only FCM are unreliable by design - Apple makes no guarantees on their delivery.

Shahulul commented 3 years ago

@mikehardy The issue is with react native camera 'TextDetector', and 'BarcodeDetectorMLKit'. When using the latest firebase SDK it causes the version mismatch when doing pod install. When just removing the react-native camera module I can update it to the latest SDK.

[!] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly": In Podfile: RNFBApp (from ../node_modules/@react-native-firebase/app) was resolved to 11.1.2, which depends on Firebase/CoreOnly (= 7.8.1)

react-native-camera/TextDetector (from `../node_modules/react-native-camera`) was resolved to 3.31.1, which depends on
  Firebase/MLVisionTextModel was resolved to 5.0.0, which depends on
    Firebase/CoreOnly (= 5.0.0)

CocoaPods could not find compatible versions for pod "Flipper-Folly": In Podfile: Flipper-Folly (= 2.3.0)

FlipperKit/Core (~> 0.33.1) was resolved to 0.33.1, which depends on
  Flipper (~> 0.33.1) was resolved to 0.33.1, which depends on
    Flipper-RSocket (~> 1.0) was resolved to 1.2.0, which depends on
      Flipper-Folly (~> 2.4)

FlipperKit/FBCxxFollyDynamicConvert (~> 0.33.1) was resolved to 0.33.1, which depends on
  Flipper-Folly (~> 2.1)
mikehardy commented 3 years ago

Your flipper issue is separate, however - for firebase you can pin the version. The MLVision stuff should still be compatible as that library was actually removed completely from firebase and was not receiving updates