fix ios push notification registration

This commit is contained in:
kanyanat 2025-12-01 14:40:13 +07:00
parent 86eec87b8c
commit 601bd7fb56
2 changed files with 166 additions and 162 deletions

13
App.js
View File

@ -31,7 +31,7 @@ TouchableOpacity.defaultProps.activeOpacity = 0.7
// setApiStore(store)
class App extends Component {
constructor (props) {
constructor(props) {
super(props)
this._setDataFromInitState = this._setDataFromInitState.bind(this)
}
@ -120,7 +120,7 @@ class App extends Component {
}
}
_setDataFromInitState () {
_setDataFromInitState() {
const appState = store.getState().app
let device = appState.device
@ -135,19 +135,22 @@ class App extends Component {
if (!device) {
this.initNotification()
} else {
this.setPermission()
this.setupNotificationListeners()
}
console.log('app state', appState, device)
}
render () {
render() {
return (
<Provider store={store}>
<PersistGate persistor={persistor} loading={null} onBeforeLift={this._setDataFromInitState}>
<StatusBar barStyle="light-content"/>
<MainNav/>
<StatusBar barStyle="light-content" />
<MainNav />
</PersistGate>
<Toast />
</Provider>

View File

@ -1,17 +1,17 @@
import React, {Component, useCallback} from 'react';
import React, { Component, useCallback } from 'react';
import { TouchableOpacity, View, Alert, ScrollView, SafeAreaView, KeyboardAvoidingView, Platform } from 'react-native'
import Image from 'react-native-fast-image'
import GetWidthHeightDevice from '../../components/GetWidthHeightDevice'
import { CustomButton } from '../../components/CustomButton'
import { CustomInput } from '../../components/CustomInput'
import {login, payment} from '../../api/UserApi'
import { login, payment } from '../../api/UserApi'
import { setToken } from '../../api/api'
import { BackgroundImage } from '../../components/BackgroundImage'
import LinearGradient from 'react-native-linear-gradient'
import Text from '../../components/Text'
import { bindActionCreators } from 'redux'
import {appSetDevice, appSetPushToken, appSetToken, appSetUser} from '../../redux/app/action'
import {connect} from 'react-redux'
import { appSetDevice, appSetPushToken, appSetToken, appSetUser } from '../../redux/app/action'
import { connect } from 'react-redux'
import IndicatorLoading from '../../components/IndicatorLoading';
import { locale, t } from '../../utils/i18n'
import moment from "moment";
@ -27,8 +27,8 @@ class LoginScreen extends Component {
password: null,
payment: [],
sum_payment: [],
all_payment : [],
room_number_array : [],
all_payment: [],
room_number_array: [],
}
this._login = this._login.bind(this)
}
@ -39,7 +39,7 @@ class LoginScreen extends Component {
}
async _login () {
async _login() {
this.setState({
isLoading: true
}, async () => {
@ -63,6 +63,7 @@ class LoginScreen extends Component {
if (enabled) {
console.log('Notification permission granted.');
await messaging().registerDeviceForRemoteMessages();
fcmToken = await messaging().getToken();
console.log('fcmToken >>>> ', fcmToken)
} else {
@ -85,14 +86,14 @@ class LoginScreen extends Component {
console.log('params >> ', params)
// console.log('fcmToken >>>>>>>>>>>>>>>>>>>>>>>>> ', fcmToken)
this.setState({isLoading:true})
this.setState({ isLoading: true })
login(params)
.then((res) => {
if (res.ok) {
if (res.data.access_token) {
setToken(res.data.access_token)
this.props.appSetToken(res.data.access_token)
this.props.navigation.navigate('HomeScreen',{isLogin:true})
this.props.navigation.navigate('HomeScreen', { isLogin: true })
let user_data = res.data.user;
this.props.appSetUser(user_data)
}
@ -119,7 +120,7 @@ class LoginScreen extends Component {
render() {
return (
<SafeAreaView style={{flex: 1}}>
<SafeAreaView style={{ flex: 1 }}>
<LinearGradient colors={['#3AA40C', '#2C7C0B']} style={{
flex: 1,
width: null,
@ -127,8 +128,8 @@ class LoginScreen extends Component {
resizeMode: 'cover'
}}>
<BackgroundImage>
<KeyboardAvoidingView style={{flex:1}} keyboardVerticalOffset={Platform.OS == 'ios' ? 70 : 0} behavior={Platform.OS == 'ios' ? "padding" : ""} enabled>
<ScrollView showsVerticalScrollIndicator={true} style={{ flex: 1}}>
<KeyboardAvoidingView style={{ flex: 1 }} keyboardVerticalOffset={Platform.OS == 'ios' ? 70 : 0} behavior={Platform.OS == 'ios' ? "padding" : ""} enabled>
<ScrollView showsVerticalScrollIndicator={true} style={{ flex: 1 }}>
<View style={styles.container}>
<View style={styles.logo}>
@ -187,9 +188,9 @@ class LoginScreen extends Component {
}}
style={styles.form_input} />
</View>
<View style={{flex: 1, marginBottom: 10}}>
<View style={{ flex: 1, marginBottom: 10 }}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('ForgetPassword')}>
<Text style={{color: '#FFF', fontSize: 15, textAlign: 'right'}}>{t('forget_password')}?</Text>
<Text style={{ color: '#FFF', fontSize: 15, textAlign: 'right' }}>{t('forget_password')}?</Text>
</TouchableOpacity>
</View>
<View style={[styles.row, { marginTop: 15 }]}>
@ -217,7 +218,7 @@ class LoginScreen extends Component {
</ScrollView>
</KeyboardAvoidingView>
</BackgroundImage>
<IndicatorLoading loadingVisible={this.state.isLoading}/>
<IndicatorLoading loadingVisible={this.state.isLoading} />
</LinearGradient>
</SafeAreaView>
)