gpt4 book ai didi

ios - RNFIREBASE MESSENGER 不适用于 iOS,但适用于 Android

转载 作者:行者123 更新时间:2023-12-05 09:04:09 26 4
gpt4 key购买 nike

推送通知适用于 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 代码片段

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;
})

签名和证书 enter image description here

enter image description here

最佳答案

iOS 上的 Firebase Messaging 需要更多配置,

首先,您需要在 AppDelegate.m 中添加此导入: #import "RNFBMessagingModule.h"

然后在这一行之后:RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

添加这一行:NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions];

然后您需要将 RCTRootView 中的 initialPropertiesnil 更改为 appProperties 这样它就像这个:

RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"RETUЯИ"initialProperties:appProperties]; <-- 从 nil 更改为 appProperties

毕竟,我们需要在 firebase 控制台中添加一个 APNs Authentication Key 文件。

转到项目设置,然后向下滚动以查看您的 ios 应用程序,您将看到 APNs Authentication Key 标题,您需要上传一个 authKey.p8 文件,或者您可以使用其他两个字段标题 APNs 证书

authKey.p8 文件需要从 app store connect 生成

  • 选择用户和访问权限,然后选择 API key 选项卡。//查看更新部分 ⏬⏬⏬
  • 点击生成 API key 或添加 (+) 按钮。
  • 为您的 key 命名,勾选“Apple Push Notifications Service”框,然后下载
  • 将 .p8 文件上传到 firebase 控制台

Update regarding authkey.p8:

  • 你需要从苹果开发者账户生成它,在auth键列表,这是link
  • instructions

当然,不要错过将 GoogleService-info.plist 文件添加到您的 example.xcworkspace,您可以在 rnfirebase.io 中查看如何执行此操作

此外,您还需要您的团队 ID,您可以从应用商店连接配置文件中获取它,生成后您将看到 key ID。

希望对你有所帮助🙏,

问候

关于ios - RNFIREBASE MESSENGER 不适用于 iOS,但适用于 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68956057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com