React-native-firebase: iOS Cloud Messaging module error (no known class method for selector [...])

Created on 20 Jul 2017  路  4Comments  路  Source: invertase/react-native-firebase

Trying to run cloud messaging in my app. It worked well for android, but I cannot make it working for iOS. iOS app doesn't compile and I get these errors:

In file included from /Users/lukaleli/Dev/myApp/ios/myApp/AppDelegate.m:14:
In file included from /Users/lukaleli/Dev/myApp/ios/../node_modules/react-native-config/ios/ReactNativeConfig/ReactNativeConfig.h:2:
../node_modules/react-native/React/Base/RCTBridgeModule.h:55:11: warning: duplicate protocol definition of 'RCTBridgeModule' is ignored
@protocol RCTBridgeModule <NSObject>
          ^
In file included from /Users/lukaleli/Dev/myApp/ios/myApp/AppDelegate.m:13:
In file included from /Users/lukaleli/Dev/myApp/ios/build/Build/Products/Debug-iphonesimulator/include/React/RCTRootView.h:12:
In file included from /Users/lukaleli/Dev/myApp/ios/build/Build/Products/Debug-iphonesimulator/include/React/RCTBridge.h:13:
/Users/lukaleli/Dev/myApp/ios/build/Build/Products/Debug-iphonesimulator/include/React/RCTBridgeModule.h:55:11: note: previous definition is here
@protocol RCTBridgeModule <NSObject>
          ^
/Users/lukaleli/Dev/myApp/ios/myApp/AppDelegate.m:66:24: error: no known class method for selector 'willPresentNotification:withCompletionHandler:'
  [RNFirebaseMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lukaleli/Dev/myApp/ios/myApp/AppDelegate.m:72:24: error: no known class method for selector 'didReceiveNotificationResponse:withCompletionHandler:'
  [RNFirebaseMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 2 errors generated.


** BUILD FAILED **



The following build commands failed:
    CompileC build/Build/Intermediates/goodly.build/Debug-iphonesimulator/goodly.build/Objects-normal/x86_64/AppDelegate.o goodly/AppDelegate.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Installing build/Build/Products/Debug-iphonesimulator/myApp.app
Launching <MY.APP.IDENTIFIER>
<MY.APP.IDENTIFIER>: 43571

My setup

Podfile

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.0'

target 'goodly' do
  pod 'React', path: '../node_modules/react-native', :subspecs => [
    'Core'
  ]

  pod 'GoogleMaps'  # <~~ remove this line if you do not want to support GoogleMaps on iOS

  # Required by RNFirebase
  pod 'Firebase/Core'
  pod 'RNFirebase', :path => '../node_modules/react-native-firebase'
  # [OPTIONAL PODS] - comment out pods for firebase products you won't be using.
  pod 'Firebase/Analytics'
  pod 'Firebase/Messaging'

end

AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "ReactNativeConfig.h"
#import <BugsnagReactNative/BugsnagReactNative.h>
#import <Firebase.h>
#import "RNFirebaseMessaging.h"

@import GoogleMaps;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSString *GOOGLE_MAPS_API_KEY = [ReactNativeConfig envFor:@"GOOGLE_MAPS_API_KEY"];
  NSURL *jsCodeLocation;
  [GMSServices provideAPIKey:GOOGLE_MAPS_API_KEY];
  [BugsnagReactNative start];
  [FIRApp configure];
  [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
  #ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  #else
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  #endif
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"wertewandel"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  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];
  return YES;
}

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

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo {
  [RNFirebaseMessaging didReceiveRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
  [RNFirebaseMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  [RNFirebaseMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)())completionHandler {
  [RNFirebaseMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}

@end

AppDelegate.h

#import <UIKit/UIKit.h>
@import UserNotifications;

@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

I did pod install after adding cloud messaging module, did fresh install with rm -rf $TMPDIR/react-* && watchman watch-del-all && rm -rf ios/build/ModuleCache/* && rm -rf node_modules/ && npm cache clean && npm install. Am I missing something?

Any help would be greatly appreciated!

Environment

  1. Target Platform: iOS
  2. Development Operating System : macOS Sierra
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant):
  4. React Native version: 0.41.2
  5. RNFirebase Version: 2.0.2

Most helpful comment

@sidferreira You haven't added the Firebase/Messaging pod

All 4 comments

@lukaleli Update to RNFirebase version 2.0.4 to fix this issue

@chrisbianca I'm having the very same issue, but with different versions. Can you help me?

PODS:
  - Firebase/Core (4.4.0):
    - FirebaseAnalytics (= 4.0.4)
    - FirebaseCore (= 4.0.9)
  - FirebaseAnalytics (4.0.4):
    - FirebaseCore (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - GoogleToolboxForMac/NSData+zlib (~> 2.1)
    - nanopb (~> 0.3)
  - FirebaseCore (4.0.9):
    - GoogleToolboxForMac/NSData+zlib (~> 2.1)
    - nanopb (~> 0.3)
  - FirebaseInstanceID (2.0.5)
  - GoogleToolboxForMac/Defines (2.1.3)
  - GoogleToolboxForMac/NSData+zlib (2.1.3):
    - GoogleToolboxForMac/Defines (= 2.1.3)
  - nanopb (0.3.8):
    - nanopb/decode (= 0.3.8)
    - nanopb/encode (= 0.3.8)
  - nanopb/decode (0.3.8)
  - nanopb/encode (0.3.8)

DEPENDENCIES:
  - Firebase/Core

SPEC CHECKSUMS:
  Firebase: 3e92884a63e8f76d107c43a67d2ab9071e1eda10
  FirebaseAnalytics: 722b53c7b32bfc7806b06e0093a2f5180d4f2c5a
  FirebaseCore: ebe73f64302705e693b1de9919a76edbdd17a19d
  FirebaseInstanceID: f2b688c66b972f30d7fa9f5f9f91455454a03b47
  GoogleToolboxForMac: 2501e2ad72a52eb3dfe7bd9aee7dad11b858bd20
  nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3

PODFILE CHECKSUM: b2f4bc894be43072b5e91736bed117ca72315a68

COCOAPODS: 1.3.1
    "react": "16.0.0-alpha.12",
    "react-native": "0.47.2",
    "react-native-firebase": "^3.0.5",

Should I add pod 'RNFirebase', :path => '../node_modules/react-native-firebase' to the Podfile?

@sidferreira You haven't added the Firebase/Messaging pod

@chrisbianca Yeah... Double shame on me... one for the error and another for forgetting to let you know. Thanks and sorry :)

Was this page helpful?
0 / 5 - 0 ratings