【发布时间】:2026-02-14 23:45:01
【问题描述】:
为什么 ExponentPush 令牌为空我 console.log 令牌显示为空 ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... .....
见下图:
push_notifications.js
import {Permissions, Notifications} from 'expo';
import axios from 'axios';
import {AsyncStorage} from 'react-native';
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 Expo.Notifications.getExpoPushTokenAsync();
await axios.post(PUSH_ENDPOINT, {token: {token}});
AsyncStorage.setItem('pushtoken', token);
}
};
【问题讨论】:
标签: javascript ios react-native push-notification