React Native Firebase ios onNotification不';t触发器
我的项目正在导入“react native firebase”,我正在尝试使用设备令牌通过firebase控制台发送测试消息。方法firebase.notifications().onNotification((notification)=>{})在android设备上触发,但在ios设备上不触发。 前台和后台都不会弹出通知。我在方法中尝试了“console.log”,但没有显示任何内容。请告诉我是什么问题。 我尝试了“onMessage()”,但它只在前台触发 这是我的密码:React Native Firebase ios onNotification不';t触发器,ios,firebase,react-native,firebase-cloud-messaging,react-native-firebase,Ios,Firebase,React Native,Firebase Cloud Messaging,React Native Firebase,我的项目正在导入“react native firebase”,我正在尝试使用设备令牌通过firebase控制台发送测试消息。方法firebase.notifications().onNotification((notification)=>{})在android设备上触发,但在ios设备上不触发。 前台和后台都不会弹出通知。我在方法中尝试了“console.log”,但没有显示任何内容。请告诉我是什么问题。 我尝试了“onMessage()”,但它只在前台触发 这是我的密码: if (Plat
if (Platform.OS == 'android') {
this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
console.log("onNotification");
console.log(notification);
notification
.setSound("default")
.android.setChannelId('default')
.android.setBigText(notification.body, notification.title, '')
// .android.setSmallIcon('@mipmap/icon_noti');
firebase.notifications().displayNotification(notification);
});
}
else {
this.notificationListener = firebase.notifications().onNotification((notification) => {
notification.setNotificationId(notification.messageId)
notification.setSound("default");
notification.setTitle(notification.data.title)
notification.ios.setBadge(notification.ios.badge ? notification.ios.badge + 1 : 0);
firebase.notifications().displayNotification(notification);
});
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 "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
#import "RNSplashScreen.h"
@import Firebase;
@import UserNotifications;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[GMSServices provideAPIKey:@"aasdfsafdadgadgadfasf"];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"asdb"
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];
[FIRApp configure];
[RNFirebaseNotifications configure];
[RNSplashScreen show];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
- (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];
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end
if(Platform.OS=='android'){
this.notificationListener=firebase.notifications().onNotification((通知:通知)=>{
console.log(“onNotification”);
控制台日志(通知);
通知
.setSound(“默认”)
.android.setChannelId('default')
.android.setBigText(notification.body,notification.title“”)
//.android.setSmallIcon(“@mipmap/icon_noti”);
firebase.notifications().displayNotification(通知);
});
}
否则{
this.notificationListener=firebase.notifications().onNotification((通知)=>{
notification.setNotificationId(notification.messageId)
通知。setSound(“默认”);
notification.setTitle(notification.data.title)
notification.ios.setBadge(notification.ios.badge?notification.ios.badge+1:0);
firebase.notifications().displayNotification(通知);
});
appDelegate.m:
#导入“AppDelegate.h”
#进口
#进口
#进口
#进口
#进口
#进口
#导入“RNFirebaseNotifications.h”
#导入“RNFirebaseMessaging.h”
#导入“RNSplashScreen.h”
@进口火基;
@导入用户通知;
@实现AppDelegate
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
[GMS服务提供密钥:@“aasdfsafdadgadfasf”];
RCTBridge*bridge=[[RCTBridge alloc]initWithDelegate:self-launchOptions:launchOptions];
RCTRootView*rootView=[[RCTRootView alloc]初始化WithBridge:bridge
模块名称:@“asdb”
初始属性:nil];
rootView.backgroundColor=[[UIColor alloc]initWithRed:1.0f绿色:1.0f蓝色:1.0f alpha:1];
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIViewController*rootViewController=[UIViewController新建];
rootViewController.view=rootView;
self.window.rootViewController=rootViewController;
[self.window makeKeyAndVisible];
[FIRApp配置];
[RNFirebaseNotifications配置];
[屏幕显示];
[[UIApplication sharedApplication]注册表项的删除];
[[UNUserNotificationCenter currentNotificationCenter]设置委托:self];
返回YES;
}
-(无效)应用程序:(UIApplication*)应用程序DidReceiveMemoteNotification:(非空NSDictionary*)用户信息
fetchCompletionHandler:(非null void(^)(UIBackgroundFetchResult))completionHandler{
[[RNFirebaseNotifications实例]DidReceiveMemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
-(void)应用程序:(UIApplication*)应用程序didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings{
[[RNFirebaseMessaging实例]didRegisterUserNotificationSettings:notificationSettings];
}
-(无效)应用程序:(UIApplication*)应用程序未收到本地通知:(UILocalNotification*)通知{
[[RNFirebaseNotifications实例]didReceiveLocalNotification:notification];
}
-(NSURL*)源URLFORBRIDGE:(RCTBridge*)桥
{
#如果调试
返回[[RCTBundleURLProvider sharedSettings]JSBundleUrlForbundlerRoot:@“索引”后备资源:nil];
#否则
返回[[NSBundle mainBundle]URLForResource:@“main”带扩展名:@“jsbundle”];
#恩迪夫
}
@结束