react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

🔥[iOS] Notifications do not come after update RN and RNF(local, background)

Open blohamen opened this issue 7 years ago • 6 comments

Issue

Describe your issue here Hi all. I have a problem with notifications on iOS after updating react-native-firebase to version 5.5.6 and react-native to 0.60.4. Android works well and receive all notifications but on iOS i can't receive any (local, background) notifications. I follow all setup guides, but nothing happend( Ps. on RN 0.59.10 and RNF 4.3.8 everything is ok

Project Files

// init notifications (executed from App.js)
import firebase from 'react-native-firebase';
import constants from './constants';
import { onTokenRefresh, processingNotificationsByType } from './services';
import { bluePale } from '../../assets/styles/variables';

const initNotifications = async () => {
    const channel = new firebase
        .notifications
        .Android
        .Channel(
            constants.channelId,
            constants.channelName,
            firebase.notifications.Android.Importance.Max,
        )
        .setDescription(constants.channelDescription);

    await firebase.notifications().android.createChannel(channel); // channel is necessary on android 8+

    const token = await firebase.messaging().getToken();
    const onTokenRefreshListener = firebase.messaging()
        .onTokenRefresh(onTokenRefresh);

    if (token) onTokenRefresh(token);

    const notificationListener = await firebase
        .notifications()
        .onNotification(async (notificationData) => { // local notifications
            const notification = new firebase.notifications.Notification()
                .setNotificationId(notificationData.notificationId)
                .setTitle(notificationData.data.type)
                .setBody(notificationData.data.body)
                .setData({
                    ...notificationData.data,
                    isLocal: true,
                })
                .android.setChannelId(constants.channelId)
                .android.setSmallIcon(constants.notificationIconName)
                .android.setLargeIcon(constants.notificationIconName)
                .android.setColorized(true)
                .android.setColor(bluePale);

            await firebase.notifications()
                .displayNotification(notification)
                .catch(err => console.error(err));

            processingNotificationsByType({
                data: notificationData,
                navigation: false,
            });
        });

    const notificationOpenedListener = await firebase
        .notifications()
        .onNotificationOpened(({ notification }) => { // background notification or user clicked on local notification
            if (notification.data.isLocal) {
                processingNotificationsByType({
                    data: notification,
                    process: false,
                });
            } else {
                processingNotificationsByType({
                    data: notification,
                });
            }
            firebase.notifications()
                .removeDeliveredNotification(notification.notificationId);
        });

    const notificationOpen = await firebase.notifications().getInitialNotification(); // remote notification
    if (notificationOpen) {
        processingNotificationsByType({
            data: notificationOpen.notification,
        });
    }

    return {
        onTokenRefreshListener,
        notificationListener,
        notificationOpenedListener,
    };
};

export {
    initNotifications,
};

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'AMIClient' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for AMIClient
  pod 'Firebase/Core', '~> 6.3.0'
  pod 'Firebase/Messaging', '~> 6.3.0'
  pod 'Fabric'
  pod 'Crashlytics'

  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/React'
  pod 'React-DevSupport', :path => '../node_modules/react-native/React'
  pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
  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-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'
  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 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation'
  pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
  pod 'RNFastImage', :path => '../node_modules/react-native-fast-image'
  pod 'RNReanimated', :path => '../node_modules/react-native-reanimated'
  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
  pod 'RNFirebase', :path => '../node_modules/react-native-firebase/ios'
  pod 'react-native-maps', :path => '../node_modules/react-native-maps'

  target 'AMIClient-tvOSTests' do
    inherit! :search_paths

  end

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

end

target 'AMIClient-tvOS' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for AMIClient-tvOS

end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "React"
      target.remove_from_project
    end
  end
end

AppDelegate.m:

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"

#import <Firebase.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
#import "RCTSplashScreen.h"
#import "AMIAPIKeys.h"
#import <Fabric/Fabric.h>
#import <Crashlytics/Crashlytics.h>
// #import <GoogleMaps/GoogleMaps.h> Uncomment this line if you want to support GoogleMaps on iOS

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // [GMSServices provideAPIKey:@"AIzaSyAVv7Ap-I3hFzDXEH7UHtZdfGju32Ab_FA"]; Uncomment this line if you want to support GoogleMaps on iOS
  [FIRApp configure];
  [RNFirebaseNotifications configure];
  [Fabric with:@[[Crashlytics class]]];

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"AMIClient"
                                            initialProperties:nil];
  [RCTSplashScreen open:rootView withImageNamed:@"splash"]; // activate splashscreen, imagename from LaunchScreen.xib

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound |
                                          UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil];

  [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  [[UIApplication sharedApplication] registerForRemoteNotifications];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (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];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"native/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:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
System:
    OS: macOS 10.14.2
    CPU: (4) x64 Intel(R) Core(TM) i7-4578U CPU @ 3.00GHz
    Memory: 5.79 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 8.11.1 - /usr/local/bin/node
    npm: 5.6.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
  IDEs:
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.4 => 0.60.4 
  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.5.6 e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • 6.3.0e.g. Instance ID
  • 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]

blohamen avatar Aug 16 '19 09:08 blohamen

I don't see the firebase notifications pod in there? I'm using RN60/RNFB556 and just tested a message from firebase console on ios 9 yesterday, it showed up and seemed to work correctly?

mikehardy avatar Aug 16 '19 13:08 mikehardy

I don't see you requesting permissions either, that's important on startup await firebase.messaging().requestPermission();

apparently it can return true even in situations where re-requesting is the difference between them showing or not, so current best practice is to put it in app bootstrap sequence and call it every time

mikehardy avatar Aug 16 '19 14:08 mikehardy

I've updated to the same versions and I bump into the same issue.

Permission is provided but 1 / 10 messages were delivered successfully to the iOS app. The firebase-admin library on the server-side returns internal-error message. Dashboard console sends successfully sometimes but mostly failed.

Can't figure out what was changed.

andrewkislev avatar Aug 22 '19 17:08 andrewkislev

Can you try creating a completely separate / clean sample app as a reproduction? Should be possible in your existing firebase account and you can alter the example name used here in order to have control over it https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh

If we can reproduce it in a completely clean way we should be able to track this down

mikehardy avatar Aug 22 '19 18:08 mikehardy

Can you try creating a completely separate / clean sample app as a reproduction? Should be possible in your existing firebase account and you can alter the example name used here in order to have control over it https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh

If we can reproduce it in a completely clean way we should be able to track this down

So, after downgrade to 5.5.0 RNF , ios notifications started to work

blohamen avatar Aug 23 '19 13:08 blohamen

That is so surprising - the changes from 5.5.0 to each version are very small https://github.com/invertase/react-native-firebase/commits/v5.x.x

what could it be? Is it possible to try each version and find the problem? Also please make absolutely certain your Xcode build is clean (this is harder than it sounds!) - I use react-native-clean-project library with react-native clean-project-auto to do it, myself

mikehardy avatar Aug 23 '19 14:08 mikehardy