仅在 iOS 上响应原生 Firebase 推送通知问题



我已经在我的项目中实现了反应原生Firebase推送通知,它可以与Android正常工作,但在iOS上没有显示。

  1. iOS 项目包括 GoogleService-info.plist 文件。
  2. 此外,在后台模式下,推送通知和远程通知的项目功能也处于"打开"状态。
  3. 我已将 APNs 身份验证密钥添加到 Firebase 控制台。
  4. 当应用在设备上运行时,它会向用户请求通知权限

预期结果: 安卓和iOS设备上的通知弹出窗口

实际结果:仅在安卓上弹出通知

应用程序运行正常,不会崩溃或引发任何错误。

AppDelegate.m 文件

#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Firebase.h> //Added This Line
#import "RNFirebaseNotifications.h" //Added This Line
#import "RNFirebaseMessaging.h" //Added This Line
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application      didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure]; //Added This Line
[RNFirebaseNotifications configure];  //Added This Line
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"pushnotificationTest" 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];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; //Added This Line
return YES;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end

我建议您重新检查 APNs 证书。 90% 的问题引用错误的 APNs 门/证书(如果您在带有调试证书的设备应用程序上安装,则需要在沙盒门中发送通知(。 如果您安装带有生产证书的应用程序,如adhock或AppStore,则需要在产品APNs门中发送通知。

您可以通过在没有Firebase的情况下发送推送通知来检查它。它可以使用此工具:https://github.com/noodlewerk/NWPusher

另外,我建议获取有关环境的更多信息:react-native-firebase版本,iOS版本,iOS SDK版本,e.t.c。

如果您在使用iOS 13时遇到问题,可以 https://github.com/invertase/react-native-firebase/issues/2565 检查此问题(maby您有同样的问题(。

我希望它对你有帮助。

最新更新