Я получаю сообщения об ошибках ниже на своем мобильном телефоне и терминале expo и, следовательно, не могу сгенерировать expo-токен для службы push-уведомлений:
Expo-токен необходим бэкэнд-серверу для отправки текстового сообщения.И я сталкиваюсь с ошибкой, генерирующей это.
Журнал экспозиционного терминала
Журнал устройства Android
push_notifications_service.js:
import { Permissions, Notifications } from 'expo';
import { AsyncStorage } from 'react-native';
import axios from 'axios';
const PUSH_ENDPOINT = "http://rallycoding.herokuapp.com/api/tokens"
export default async () => {
let previousToken = await AsyncStorage.getItem('pushtoken');
console.log(previousToken);
if (previousToken) {
return;
} else {
let { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
if (status !== 'granted') {
return;
}
let token = await Notifications.getExpoPushTokenAsync();
await axios.post(PUSH_ENDPOINT, { token: { token } });
AsyncStorage.setItem('pushtoken', token);
}
};
App.js:
import React from 'react';
import { StyleSheet, View, Alert } from 'react-native';
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import ReduxThunk from 'redux-thunk';
import { createBottomTabNavigator } from 'react-navigation';
import reducers from './reducers';
import { Notifications } from 'expo';
import LoginScreen from './Modules/Authentication/LoginScreen';
import SignUpScreen_1 from './Modules/Authentication/SignUpScreen_1';
import SignUpScreen_2 from './Modules/Authentication/SignUpScreen_2';
import ConfirmationScreen from './Modules/Authentication/ConfirmationScreen'
import ForgotPasswordScreen from './Modules/Authentication/ForgotPasswordScreen';
import LibraryNotificationScreen from './Modules/Library/LibraryNotificationScreen';
import BarCodeScannerScreen from './Modules/Library/BarCodeScanner'
import FreshArrivalsList from './Modules/Library/FreshArrivalsList';
import AllBooksListScreen from './Modules/Library/AllBooksListScreen';
import registerForPushNotificationsAsync from './Modules/Services/push_notifications_service.js'
export default class App extends React.Component {
componentDidMount() {
registerForPushNotificationsAsync();
// Handle notifications that are received or selected while the app
// is open. If the app was closed and then opened by tapping the
// notification (rather than just tapping the app icon to open it),
// this function will fire on the next tick after the app starts
// with the notification data.
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
_handleNotification = (notification) => {
this.props.navigation.navigate('libraryNotifications');
};
render() {
const MainNavigator = createBottomTabNavigator({
library: {
screen: createBottomTabNavigator({
all_books_list: { screen: AllBooksListScreen },
freshArrivals: { screen: FreshArrivalsList },
})
},
barCodeScanner: { screen: BarCodeScannerScreen },
libraryNotifications: { screen: LibraryNotificationScreen},
login: { screen: LoginScreen },
forgot_password: { screen: ForgotPasswordScreen },
sign_up: {
screen: createBottomTabNavigator({
sign_up_1: { screen: SignUpScreen_1 },
sign_up_2: { screen: SignUpScreen_2 },
otp_confirmation: { screen: ConfirmationScreen }
}, {
navigationOptions: {
tabBarVisible: false
}
})
}
}, {
navigationOptions: {
tabBarVisible: false
}, lazy: true
});
const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));
return (
<Provider store={store}>
<View style={styles.container}>
<MainNavigator />
</View>
</Provider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
justifyContent: 'center',
},
});