Please help i have been struggling with how to get the push token for days now but all to no avail.
here is my code
import React, { useEffect } from “react”;
import { createBottomTabNavigator } from “@react-navigation/bottom-tabs”;
import { MaterialCommunityIcons } from “@expo/vector-icons”;
import ListingsEditScreen from “…/screens/ListingsEditScreen”;
import FeedNavigator from “./FeedNavigator”;
import AccountNavigator from “./AccountNavigator”;
import NewListingButton from “./NewListingButton”;
import * as Permissions from “expo-permissions”;
import * as Notifications from “expo-notifications”;
const Tab = createBottomTabNavigator();
const AppNavigator = () => {
useEffect(() => {
registerForpushNotification();
}, []);
};
const registerForpushNotification = async () => {
try {
const permission = await Permissions.askAsync(Permissions.NOTIFICATIONS); // permission granted only once
if (!permission.granted) return;
const token = await Notifications.getExpoPushTokenAsync(); //get notification token
console.log(token);
} catch (error) {
console.log("error getting push token", error);
}