Closed
Description
Issue:
Not able to receive notification on iOS device
What I've tried:
I've followed this documentation to implement notifications in iOS,
https://rnfirebase.io/docs/v4.2.x/notifications/ios
iOS implementation:
AppDelegate.m
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
@import Firebase;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/// Firebase configuration
[FIRApp configure];
[RNFirebaseNotifications configure];
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"XYZApp"
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 {
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}
- (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];
}
@end
Application's Home File
componentDidMount() {
/// get permission and reuest FCM token
this.notificationRequestPermission()
/// Triggered when a particular notification has been displayed
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
console.log("NOTIFICATION DISPLAYED", notification)
});
/// Triggered when a particular notification has been received
this.notificationListener = firebase.notifications().onNotification((notificationobj) => {
// Process your notification as required
console.log("NOTIFICATION RECEIVED", notificationobj)
});
/// Listen for a notification being opened
// Foreground or Background
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
// Get the action triggered by the notification being opened
});
// App closed
firebase.notifications().getInitialNotification()
.then((notificationOpen) => {
if (notificationOpen) {
// App was opened by a notification
}
});
}
Can somebody guide me in this, is there any other implementation way to receive notification in iOS
Metadata
Metadata
Assignees
Labels
No labels