gpt4 book ai didi

ios - react-native-firebase notifications().onNotification() 从不在 ios 中调用

转载 作者:行者123 更新时间:2023-11-28 23:23:30 25 4
gpt4 key购买 nike

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

版本

- "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. I uploaded an APN key to the firebase project.

  2. I put GoogleService-info.plist in my project.

  3. Here is my AppDelegate.m

#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) 在 Project Navigator 中,右键单击 Libraries > Add Files To 。导航到/node_modules/react-native-firebase/ios/。选择 RNFirebase.xcodeproj 并单击添加按钮。

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

c) 转到 Build Settings,找到 Header Search Path,双击它的值并按“+”按钮。在那里添加以下行:$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase

d) 使用“Cmd +Shift + Enter + K”键清除缓存然后构建项目。现在 xcode 应该可以识别 firebase 依赖项。

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

关于ios - react-native-firebase notifications().onNotification() 从不在 ios 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59259307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com