我有一个聊天应用程序,一旦用户收到新消息或数据库中的任何相关活动,便会通知用户。我正在使用react-native-firebase在用户电话上显示本地通知。我通过添加必需的pod来遵循通知的安装和设置指南:
但是,即使我处于后台模式或前台模式,我也看不到本地通知。
这是显示通知的代码:
const notification = new firebase.notifications.Notification()
.setNotificationId('1')
.setTitle('My notification title')
.setBody('My notification body')
.setData({});
notification.ios.setBadge(2)
firebase.notifications().displayNotification(notification)
Pod文件:
platform :ios, '9.0'
pod 'Firebase'
pod 'Firebase/Database', '~> 6.3.0'
pod 'Firebase/Auth', '~> 6.3.0'
pod 'Firebase/Messaging', '~> 6.3.0'
target 'ChattieEm' do
# Comment the next line if you don't want to use dynamic frameworks
#use_frameworks!
# Pods for ChattieEm
#target 'ChattieEm-tvOSTests' do
# inherit! :search_paths
# Pods for testing
#end
#pod 'react-native-randombytes', :path => '../node_modules/react-native-randombytes'
#pod 'react-native-udp', :path => '../node_modules/react-native-udp'
target 'ChattieEmTests' do
inherit! :search_paths
# Pods for testing
end
end
AppDelegate.m:
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[RNFirebaseNotifications configure];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"ChattieEm"
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];
return YES;
}
- (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
谁能说出问题所在或我做错了什么?
编辑:
我测试过的模拟器正在运行 iOS 12