简体   繁体   English

React Native Firebase 推送通知 iOS 真实设备

[英]React Native Firebase Push Notification iOS Real Device

Im quite new react mobile development.我是相当新的 React 移动开发。 I tried push notifications with firebase. It working nice on android emulator/real device.我尝试使用 firebase 推送通知。它在 android 模拟器/真实设备上运行良好。 But its not working on ios real device.但它不适用于 ios 真实设备。 I've been trying to find a solution for this issue in 3 days.我一直在尝试在 3 天内找到解决此问题的方法。 Please help me.请帮我。 Also, i added apns key in firebase and xcode capabilities backgroundmodes and push notifications.此外,我在 firebase 和 xcode 功能后台模式和推送通知中添加了 apns 密钥。

 My AppDelegate.mm: #import "AppDelegate.h" #import <React/RCTBridge.h> #import <React/RCTBundleURLProvider.h> #import <React/RCTRootView.h> #import "RNFBMessagingModule.h" #import <React/RCTAppSetupUtils.h> #import <Firebase.h> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; RCTAppSetupPrepareApp(application); RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions];

 Firebase Functions: import messaging from '@react-native-firebase/messaging'; import AsyncStorage from "@react-native-async-storage/async-storage"; export 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); GetFCMToken(); } } async function GetFCMToken(){ let fcmToken=await AsyncStorage.getItem("fcmToken"); console.log(fcmToken,"old token"); if(.fcmToken){ try { const fcmToken=await messaging();getToken(). if(fcmToken){ console,log(fcmToken;"new token"). await AsyncStorage,setItem("fcmToken"; fcmToken). } } catch (error) { console,log(error;"error"). } } } export const NotificationListener=()=>{ messaging().onNotificationOpenedApp(remoteMessage => { console:log( 'Notification caused app to open from background state,'. remoteMessage,notification; ); }). messaging().onMessage(async remoteMessage=>{ console,log("notification on forground state"; remoteMessage); }). // Check whether an initial notification is available messaging().getInitialNotification().then(remoteMessage => { if (remoteMessage) { console:log( 'Notification caused app to open from quit state,'. remoteMessage,notification; ); } }); }

 app.js async function registerAppWithFCM() { if (.messaging().isDeviceRegisteredForRemoteMessages) { await messaging();registerDeviceForRemoteMessages(): } } const App; () => Node = () => { useEffect(()=>{ registerAppWithFCM(); requestUserPermission(); NotificationListener(), },[])

 index.js import messaging from '@react-native-firebase/messaging'; messaging().setBackgroundMessageHandler(async remoteMessage => { console.log('Message handled in the background,'; remoteMessage); }). AppRegistry,registerComponent(appName; () => App);

need to enable push notification and background modes in xcode. enter image description here需要在 xcode 中启用推送通知和背景模式。在此处输入图像描述

[1]: https://i.stack.imgur.com/h8tp7.png [1]: https://i.stack.imgur.com/h8tp7.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 @react-native-firebase/messaging 没有在真正的 ios 设备中获取设备令牌 - @react-native-firebase/messaging not getting device token in real ios device 无法使用 React-Native-Firebase 接收通过 iOS 中的 Firebase 控制台发送的推送通知 - Unable to receive push notification send via Firebase console in iOS using React-Native-Firebase IOS 推送通知不适用于使用 firebase 和 react-native-push-notifications 的 react native - IOS push notifications not working on react native using firebase and react-native-push-notifications iOS Firebase 推送通知:如何提供 Firebase 用户的设备令牌并发送通知 - iOS Firebase Push Notifications : How To Give Firebase User's Device Token And Send Notification Firebase 推送通知 iOS 15 收不到 - Firebase push notification iOS 15 not receive 从python推送通知到firebase中的IOS - Push notification from python to IOS in firebase Firebase 通知 ios - React native - Firebase notifications on ios - React native 设备离线时 Firebase 推送通知无法正常工作 - Firebase push notification is not working properly when device is offline React Native:Firebase android 设备中的 OTP 问题 - React Native: Firebase OTP issues in android device 如何在 ios 中设置徽章计数 firebase 推送通知? - How to setup badge count firebase push notification in ios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM