react-native-firebase notifications().onNotification() 永远不会在



我从 firebase 控制台发送了测试消息,但 firebase.notifications((.onNitification((notification :Notification(=>{ 控制台.log(通知(; }( 从未被调用。

版本

- "react-native": "^0.61.2",
- "react-native-firebase": "^5.5.6", 

豆荚文件

1. pod 'RNFirebase', :path => '../node_modules/react-native-firebase/ios'
2. pod 'Firebase/Core', '~> 6.3.0'
3. pod 'Firebase/Messaging', '~> 6.3.0'

我所做的是...

  1. 我上传了一个 APN 密钥到火力基地项目。

  2. 我把GoogleService-info.plist放在我的项目中。

  3. 这是我的应用代表

#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <GoogleMaps/GoogleMaps.h>
#import <Firebase.h>
#import <FirebaseMessaging.h>
#import "RNFirebaseMessaging.h"
#import "RNFirebaseNotifications.h"
#import "RNSplashScreen.h"
@import Firebase;
@import UserNotifications;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[RNFirebaseNotifications configure];
[GMSServices provideAPIKey:@""];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@""
initialProperties:nil];
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]; 
[RNSplashScreen show]; 
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];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end
  1. 这是我的代码
this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
alert('in method')
console.log("onNotification");
console.log(notification);
notification.setSound("default");
notification.ios.setBadge(notification.ios.badge ? notification.ios.badge + 1 : 0);
firebase.notifications().displayNotification(notification);
});

根据您提供的信息,只是一些疯狂的猜测:

1( 在 Xcode 的功能选项卡中,打开:

a( 推送通知

b( 后台模式 - 仅检查远程通知

2( 检查构建阶段:

a( 在项目导航器中,右键单击 库> 将文件添加到 。导航到/node_modules/react-native-firebase/ios/。选择 RNFirebase.xcodeproj然后单击添加按钮。

b( 再次单击"+",选择 libRNFirebase.a 并添加它。如果找不到它,请清理并构建项目。

c( 转到构建设置,找到标题搜索路径,双击其值并按"+"按钮。在此处添加以下行: $(SRCROOT(/../node_modules/react-native-firebase/ios/RNFirebase

d( 使用"Cmd + Shift + Enter + K"键清除缓存,然后构建项目。现在,xcode 应该可以识别 Firebase 依赖项。

e( 使用"Cmd + Shift + Enter + K"键清除缓存,然后构建项目。现在,xcode 应该可以识别 Firebase 依赖项。

最新更新