upd: clear warning
Deskripsi: - update firebase > clear warning No Issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { getApp, getApps, initializeApp } from '@react-native-firebase/app';
|
||||
import messaging, { getMessaging } from '@react-native-firebase/messaging';
|
||||
import { getMessaging, registerDeviceForRemoteMessages, setAutoInitEnabled } from '@react-native-firebase/messaging';
|
||||
import * as Notifications from 'expo-notifications';
|
||||
import { useEffect } from 'react';
|
||||
import { PermissionsAndroid, Platform } from 'react-native';
|
||||
|
||||
@@ -20,20 +20,8 @@ const initializeFirebase = async () => {
|
||||
try {
|
||||
const app = getApps().length ? getApp() : initializeApp(RNfirebaseConfig);
|
||||
const mess = getMessaging(app);
|
||||
|
||||
await messaging().registerDeviceForRemoteMessages();
|
||||
|
||||
// Set auto initialization and background message handler
|
||||
mess.setAutoInitEnabled(true);
|
||||
// mess.setBackgroundMessageHandler(async remoteMessage => {
|
||||
// const screen = remoteMessage?.data?.category;
|
||||
// const content = remoteMessage?.data?.content;
|
||||
|
||||
// if (screen && content) {
|
||||
// await AsyncStorage.setItem('navigateOnOpen', JSON.stringify({ screen, content }));
|
||||
// }
|
||||
// });
|
||||
|
||||
await registerDeviceForRemoteMessages(mess);
|
||||
setAutoInitEnabled(mess, true);
|
||||
return mess
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize Firebase:', error);
|
||||
@@ -53,8 +41,10 @@ export const requestPermission = async () => {
|
||||
}
|
||||
return false
|
||||
}
|
||||
} else if (Platform.OS === 'ios') {
|
||||
const { status } = await Notifications.requestPermissionsAsync();
|
||||
return status === 'granted';
|
||||
}
|
||||
return true
|
||||
} catch (err) {
|
||||
console.warn('Error requesting notification permissions:', err);
|
||||
}
|
||||
@@ -62,8 +52,8 @@ export const requestPermission = async () => {
|
||||
|
||||
export const getToken = async () => {
|
||||
try {
|
||||
await initializeFirebase();
|
||||
const token = await messaging().getToken();
|
||||
const mess = await initializeFirebase();
|
||||
const token = await mess?.getToken();
|
||||
return token;
|
||||
} catch (error) {
|
||||
console.error("Error getting token:", error);
|
||||
@@ -74,8 +64,6 @@ export const useNotification = () => {
|
||||
useEffect(() => {
|
||||
const initializeAndSetup = async () => {
|
||||
try {
|
||||
// await initializeFirebase();
|
||||
// await requestPermission();
|
||||
await getToken();
|
||||
} catch (error) {
|
||||
console.error('Failed to setup notifications:', error);
|
||||
|
||||
Reference in New Issue
Block a user