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);
}
Is anything being logged by your console.log statements? What if you put a console.log at the top of your registerForpushNotification function, does it get logged?
yes i logged the token on the console
see here i extracted this line from the code above:
that is the line to get the token
const token = await Notifications.getExpoPushTokenAsync(); //get notification token
console.log(token);
But the token isn’t being logged? What if you add a console.log('test') at the top of your registerForpushNotification function, do you see test in the ouput?
thanks i think i got it now however the package is deprecated
Please have a look here for a solution:
Hello!
I’m going through the Notification section in the advanced react native, and I received an error message " expo-permissions is now deprecated — the functionality has been moved to other expo packages that directly use these permissions (e.g. expo-location, expo-camera). The package will be removed in the upcoming releases."
Not sure what I need to do for this section of the code. Please let me know if you have any idea!
import * as Notifications from “expo-notifications”;
import * as …