"react-native": "0.41.2",
"react-native-fcm": "^6.0.2"
Iphone 5s IOS 9.3.2, Xcode 8.2.1
Config: https://firebase.google.com/docs/cloud-messaging/ios/certs
and my code AppDelegate.h:
@import UserNotifications;
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
and file AppDelegate.m:
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNFIRMessaging.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"appFirebase"
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];
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:``(UNNotification *)notification withCompletionHandler:(void (^)``(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler
{
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
@end
but FCM on Firebase Panel Don't Work When I exit this app.
it might not work in debug mode, try in the release mode (remember to upload APNS cers to firebase)
Did you enable Push Notification in Capabilites ?
I still received notifications in ios(release mode), but when I exit my app, FCM on Firebase Panel Don't Work.
I'm not sure about your case "FCM on Firebase Panel". My case, run react-native run-ios and
...
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
console.log('notificationListener',notif)
...
}
...
Make a test push from server
# api_key=<server key>
# curl --header "Authorization: key=$api_key" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d '{"to":"<fcm token>","priority":"high","notification":{"title":"Your Title","text":"Your Text"},"data":{"badge":1,"alert":"New data is available"}}'
=> got a log from console.log('notificationListener',notif) => so online notification works!
Next, force close app, make another test push from server => didn't see any notification banner on device => offline notification doesn't work!!!
Open ios project with Xcode, Enable Push Notification

Result:

=> it shows this banner for both cases online, offline, force close app
I've done what @tamhv wrote but i still not receiving notification when app is closed or in background. I receive notification only in foreground.
Debugging on XCode i saw that this method is never called:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
I'm on XCode 8.0, iOS 10.2 on iPhone 6
My Push Notifications on Capabilites are enabled , and also "Remote notifications" on Background Mode.
Did you upload correct .p12 to firebase console?
https://firebase.google.com/docs/cloud-messaging/ios/certs
Damn !!
@tamh you are right... i missed .p12 !
Many thanks
Thank you very much! I love github 馃憤 ...
Most helpful comment
Did you upload correct .p12 to firebase console?
https://firebase.google.com/docs/cloud-messaging/ios/certs