问题描述
在 Android 上收到后台通知,但在 React Native 上的 IOS 上不收到。
index.js
-ln
这是在注册组件之前调用的,如某些 Github 问题中所述。
迁移到 react native firebase v6 后出现这个问题。
软件包版本:-
messaging().setBackgroundMessageHandler(async (message)=>{
console.log(message)
});
AppDelegate.m
"@react-native-firebase/app": "^11.0.0","@react-native-firebase/messaging": "^11.0.0"
AppDelegate.h
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
static void Initializeflipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addplugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addplugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addplugin:[FlipperKitReactPlugin new]];
[client addplugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
#import <GoogleMaps/GoogleMaps.h>
#import <Firebase.h>
#import <React/RCTLinkingManager.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef FB_SONARKIT_ENABLED
Initializeflipper(application);
#endif
[GMSServices provideAPIKey:@"AIzaSyA19U0nRV9PKyWHz-252DKVkShrzooWt5Q"];
[FIRApp configure];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"Sociana"
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;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<Nsstring *,id> *) options {
return [RCTLinkingManager application:app openURL:url options:options];
//return [self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import "RNAppAuthAuthorizationFlowManager.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate,RCTBridgeDelegate,RNAppAuthAuthorizationFlowManager>
@property (nonatomic,strong) UIWindow *window;
@property(nonatomic,weak)id<RNAppAuthAuthorizationFlowManagerDelegate>authorizationFlowManagerDelegate;
@end
我使用了外部设备进行测试,在 xcode 和 Apple 开发帐户中启用了所有后台模式和推送通知。
当前的 xcode 版本是 apns: {
payload: {
aps: {
"content-available": "true"
}
},headers: {
"apns-priority": "10",}
}
任何帮助将不胜感激。谢谢!
解决方法
将 apns
标头中 content-available 的值替换为 1 而不是“true”:
"content-available":1