fix: gradle
This commit is contained in:
@@ -2,7 +2,7 @@ import axios from 'axios';
|
||||
|
||||
const api = axios.create({
|
||||
// baseURL: 'http://10.0.2.2:3000/api',
|
||||
baseURL: 'http://192.168.1.243:3000/api',
|
||||
baseURL: 'https://stg-darmasaba.wibudev.com/api',
|
||||
});
|
||||
|
||||
export const apiCheckPhoneLogin = async (body: { phone: string }) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import firebase from '@react-native-firebase/app';
|
||||
import messaging from '@react-native-firebase/messaging';
|
||||
import { getApp, getApps, initializeApp } from '@react-native-firebase/app';
|
||||
import { getMessaging } from '@react-native-firebase/messaging';
|
||||
import { useEffect } from 'react';
|
||||
import { PermissionsAndroid } from 'react-native';
|
||||
|
||||
@@ -14,24 +14,21 @@ const RNfirebaseConfig = {
|
||||
databaseURL: "https://mobile-darmasaba-default-rtdb.asia-southeast1.firebasedatabase.app/"
|
||||
};
|
||||
|
||||
let initialized = false;
|
||||
|
||||
const initializeFirebase = async () => {
|
||||
if (initialized) return;
|
||||
|
||||
try {
|
||||
if(!firebase.apps.length){
|
||||
firebase.initializeApp(RNfirebaseConfig)
|
||||
}
|
||||
const app = getApps().length ? getApp() : initializeApp(RNfirebaseConfig);
|
||||
const mess = getMessaging(app);
|
||||
|
||||
// Set auto initialization and background message handler
|
||||
messaging().setAutoInitEnabled(true);
|
||||
messaging().setBackgroundMessageHandler(async remoteMessage => {
|
||||
mess.setAutoInitEnabled(true);
|
||||
mess.setBackgroundMessageHandler(async remoteMessage => {
|
||||
console.log('Message handled in the background!', remoteMessage);
|
||||
});
|
||||
|
||||
return mess
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize Firebase:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -40,11 +37,7 @@ const requestPermission = async () => {
|
||||
const granted = await PermissionsAndroid.request(
|
||||
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
|
||||
);
|
||||
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
|
||||
console.log('Notification permission granted');
|
||||
} else {
|
||||
console.log('Notification permission denied');
|
||||
}
|
||||
return granted;
|
||||
} catch (err) {
|
||||
console.warn('Error requesting notification permissions:', err);
|
||||
}
|
||||
@@ -52,12 +45,12 @@ const requestPermission = async () => {
|
||||
|
||||
const getToken = async () => {
|
||||
try {
|
||||
const token = await messaging().getToken();
|
||||
const mess = await initializeFirebase();
|
||||
const token = await mess?.getToken();
|
||||
console.log('Token:', token);
|
||||
return token;
|
||||
} catch (error) {
|
||||
console.error("Error getting token:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,7 +58,7 @@ export const useNotification = () => {
|
||||
useEffect(() => {
|
||||
const initializeAndSetup = async () => {
|
||||
try {
|
||||
await initializeFirebase();
|
||||
// await initializeFirebase();
|
||||
await requestPermission();
|
||||
await getToken();
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user