- I installed FB Sdk to my react-native project
- generated certificates for both, ios and android platforms
- set capabilities such a "push notifications" and "background-mode -> remote notifications".
my Appdelegate.m(cut version)
#import "AppDelegate.h"#import <React/RCTBridge.h>#import <React/RCTBundleURLProvider.h>#import <React/RCTRootView.h>#import <GoogleMaps/GoogleMaps.h>#import <Firebase.h>#import "RNFBMessagingModule.h"@import UserNotifications;@interface AppDelegate () <UNUserNotificationCenterDelegate>@end@implementation AppDelegateNSString *const kGCMMessageIDKey = @"gcm.message_id";- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ if ([FIRApp defaultApp] == nil) { [FIRApp configure]; } [FIRMessaging messaging].delegate = self; NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions]; if ([UNUserNotificationCenter class] != nil) { // iOS 10 or later // For iOS 10 display notification (sent via APNS) [UNUserNotificationCenter currentNotificationCenter].delegate = self; UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge; [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) { // ... }]; } else { // iOS 10 notifications aren't available; fall back to iOS 8-9 notifications. UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; [application registerUserNotificationSettings:settings]; } [application registerForRemoteNotifications]; return YES;}// [START receive_message]- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { // 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);}- (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.- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { NSDictionary *userInfo = notification.request.content.userInfo; // 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.- (void)userNotificationCenter:(UNUserNotificationCenter *)centerdidReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler { NSDictionary *userInfo = response.notification.request.content.userInfo; if (userInfo[kGCMMessageIDKey]) { NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]); } // 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]- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken { NSLog(@"FCM registration token: %@", fcmToken); // Notify about received token. NSDictionary *dataDict = [NSDictionary dictionaryWithObject:fcmToken forKey:@"token"]; [[NSNotificationCenter defaultCenter] postNotificationName: @"FCMToken" object:nil userInfo:dataDict]; // TODO: If necessary send token to application server. // Note: This callback is fired at each app startup and whenever a new token is generated.}// [END refresh_token]- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Unable to register for remote notifications: %@", error);}// 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.- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"APNs device token retrieved: %@", deviceToken); // With swizzling disabled you must set the APNs device token here. // [FIRMessaging messaging].APNSToken = deviceToken;}@end
my Appdelegate.h
#import <React/RCTBridgeDelegate.h>#import <UIKit/UIKit.h>@import Firebase;@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, FIRMessagingDelegate>@property (nonatomic, strong) UIWindow *window;@end
- after launching app I request user permission to send notifications
- I generate device token and store it in AsyncStorage(and push it to my server)
I successfully signed in to FB ios project, which is displayed in my FB console.After launching ios simulator or real device plugged in by usb I try to emit some remote notification and my onMessage listeners does not catch anything.
ps. when I used prev version of FB I configured it successfully.