zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.73k stars 2.05k forks source link

How to implement react-native-push-notification with latest RN version 0.71.0 #2344

Closed russelRajitha closed 1 year ago

russelRajitha commented 1 year ago

I have installed the latest version of React native and apparently, it has some changes with delegate files that we used to add push notification event handlers. so how to config this library with this latest version?

AppDelegate.h

#import <RCTAppDelegate.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : RCTAppDelegate

@end
AppDelegate.mm

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"i4tEmployee";
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
  return true;
}

@end
BZaldua commented 1 year ago

@russelRajitha I had the same issue and found the solution in here: https://github.com/react-native-push-notification/ios/issues/388#issuecomment-1387194321

Hope it helps!

RnbWd commented 1 year ago

I also ran into this issue, just adding <UNUserNotificationCenterDelegate>

like this

#import <RCTAppDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UNUserNotificationCenter.h>

@interface AppDelegate : RCTAppDelegate <UNUserNotificationCenterDelegate>

@end

fixed it for me

dezudas commented 1 year ago

I also ran into this issue, just adding <UNUserNotificationCenterDelegate>

like this

#import <RCTAppDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UNUserNotificationCenter.h>

@interface AppDelegate : RCTAppDelegate <UNUserNotificationCenterDelegate>

@end

fixed it for me

what about AppDelegate.mm changes?

DanielGannage commented 1 year ago

Also having this issue with Android after upgrading to 0.71. Nothing seems to pop up when app is in background. However - no errors, so hard to figure out.

Permissions are all there and I have background/foreground tasks working for other stuff.

R0LLeX commented 1 year ago

@DanielGannage, I have the same problem on android, have you found some solution?

russelRajitha commented 1 year ago

This is now working fine. thanks all for the support