You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.2 KiB
70 lines
2.2 KiB
import React, { useEffect } from 'react';
|
|
import { StyleSheet, StatusBar, Platform, PermissionsAndroid } from 'react-native';
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
import { RootNavigator } from './src/navigation';
|
|
import { useAuthStore, useUserStore, useNotificationStore, usePushStore } from './src/store';
|
|
import { COLORS } from './src/utils/constants';
|
|
import Toast from 'react-native-toast-message';
|
|
import { easemobService } from './src/services/easemob';
|
|
|
|
|
|
function App() {
|
|
const { initialize: initAuth } = useAuthStore();
|
|
const { initialize: initUser } = useUserStore();
|
|
const { loadSettings } = useNotificationStore();
|
|
const { initCloud } = usePushStore();
|
|
|
|
useEffect(() => {
|
|
async function initialize() {
|
|
await initAuth();
|
|
await initUser();
|
|
loadSettings();
|
|
await initCloud();
|
|
if (Platform.OS === 'android' && Platform.Version >= 33) {
|
|
try {
|
|
const granted = await PermissionsAndroid.request(
|
|
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
|
|
{
|
|
title: '通知权限',
|
|
message: '青核校园需要通知权限来接收消息提醒',
|
|
buttonNeutral: '稍后',
|
|
buttonNegative: '取消',
|
|
buttonPositive: '允许',
|
|
}
|
|
);
|
|
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
|
|
console.log('[Push] Android通知权限已授予');
|
|
}
|
|
} catch (error) {
|
|
console.warn('[Push] 请求通知权限失败:', error);
|
|
}
|
|
}
|
|
easemobService.init().catch(() => {});
|
|
}
|
|
initialize();
|
|
}, [initAuth, initUser, loadSettings, initCloud]);
|
|
|
|
return (
|
|
<SafeAreaView style={styles.container}>
|
|
<StatusBar
|
|
barStyle="dark-content"
|
|
backgroundColor={COLORS.background}//设置statusBar背景颜色
|
|
translucent={false}
|
|
/>
|
|
<NavigationContainer>
|
|
<RootNavigator />
|
|
</NavigationContainer>
|
|
<Toast />
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: COLORS.background,
|
|
},
|
|
});
|
|
|
|
export default App;
|