react-native-firebase notifications().onNotification() 从未在 ios 中被调用
react-native-firebase notifications().onNotification() is never called in ios
我从 firebase 控制台发送了测试消息,但是 firebase.notifications().onNitification((notification :Notification)=>{
console.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'
我所做的是...
I uploaded an APN key to the firebase project.
I put GoogleService-info.plist in my project.
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
- 这是我的代码
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/。 Select RNFirebase.xcodeproj 并单击“添加”按钮。
b) 再次点击“+”,select 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 依赖项
我从 firebase 控制台发送了测试消息,但是 firebase.notifications().onNitification((notification :Notification)=>{ console.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'
我所做的是...
I uploaded an APN key to the firebase project.
I put GoogleService-info.plist in my project.
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
- 这是我的代码
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/。 Select RNFirebase.xcodeproj 并单击“添加”按钮。
b) 再次点击“+”,select 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 依赖项