【发布时间】:2021-10-27 13:11:39
【问题描述】:
推送通知适用于 Android,但不适用于 iOS。我已经在设备上进行了测试,并通过了测试飞行,因为不支持模拟器
我已完成 iOS 所需的额外设置。
以下是我的 package.json 文件中的相关信息
包.json
"name": "####",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/async-storage": "*",
"@react-native-community/masked-view": "*",
"@react-native-firebase/analytics": "*",
"@react-native-firebase/app": "*",
"@react-native-firebase/auth": "*",
"@react-native-firebase/firestore": "*",
"@react-native-firebase/messaging": "*",
"prop-types": "*",
"react": "16.13.1",
"react-dom": "^17.0.2",
"react-native": "0.63.4",
"react-native-fbsdk": "*",
"react-native-gesture-handler": "*",
"react-native-reanimated": "^1.0.0-alpha",
"react-native-render-html": "*",
"react-native-safe-area-context": "*",
"react-native-screens": "*",
"react-navigation": "^4.4.4",
"react-navigation-drawer": "^2.7.1",
"react-navigation-stack": "^2.10.4",
"react-navigation-tabs": "^2.11.1",
"typescript": "^4.2.4"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@react-native-community/eslint-config": "^1.1.0",
"babel-jest": "^25.1.0",
"eslint": "^6.5.1",
"jest": "^25.1.0",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "16.13.1"
},
"jest": {
"preset": "react-native"
}
}
包含在 index.js 中,我在其中添加了相应的 react-native-firebase 代码 sn-ps
import messaging from '@react-native-firebase/messaging';
// Register background handler
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Hey');
console.log('Message handled in the background!', remoteMessage);
});
const Applicaiton: () => React$Node = () => {
useEffect(() => {
console.log('RN Message Called on USEFFECT!');
const unsubscribe = messaging().onMessage(async remoteMessage => {
Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
return unsubscribe;
}, []);
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
}
AppDelegate.m
#import "AppDelegate.h"
#import <Firebase.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"appName"
initialProperties:nil];
Xcode 目标输出标记了 Firebase 的一些问题
2021-08-27 11:23:39.606662-0400 appName[69219:5588124] 8.1.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` "(`FirebaseApp.configure()`" in Swift) to your application initialization. Read more:
2021-08-27 11:23:39.700654-0400 appName[69219:5588429] 8.1.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2021-08-27 11:23:39.706694-0400 appName[69219:5588429] 8.1.0 - [Firebase/Analytics][I-ACS023007] Analytics v.8.1.0 started
2021-08-27 11:23:39.751967-0400 appName[69219:5588429] 8.1.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see )
2021-08-27 11:23:39.799721-0400 appName[69219:5578599] [native] Running application appName ({
initialProps = {
};
rootTag = 1;
})
【问题讨论】:
标签: ios react-native firebase-cloud-messaging react-native-firebase