i was struggling to solve an issue in push notivication as you know the course of my dear teacher mosh hamadani isn’t sutaible now beacuse many thinks have been changed .
the error that i have is this “expo-notifications functionality is not fully supported in Expo Go:
We recommend you instead use a development build to avoid limitations. Learn more: https://expo.fyi/dev-client.“
this is my main navigator
import {
View,
StyleSheet,
Text,
TouchableOpacity,
Platform,
} from "react-native";
import React, { useEffect, useState } from "react";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import ListingEditscreen from "../screens/ListingEditscreen";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import FeedNavigator from "./FeedNavigator";
import AccoutNavigator from "./AccoutNavigator";
import * as Notifications from "expo-notifications";
import Constants from "expo-constants";
import * as Device from "expo-device";
const Tab = createBottomTabNavigator();
export default function MainNavigator() {
const [expoToken, setExpoToken] = useState("");
useEffect(() => {
registerForPushNotificationsAsync().then((token) => {
if (token) {
setExpoToken(token);
console.log("Expo Push Token:", token);
}
});
}, []);
return (
<View style={{ flex: 1 }}>
<Tab.Navigator
screenOptions={{
headerShown: false,
tabBarActiveTintColor: "tomato",
tabBarButton: (props) => (
<TouchableOpacity {...props} activeOpacity={1} />
),
}}
>
<Tab.Screen
name="Listings"
component={FeedNavigator}
options={{
tabBarIcon: ({ size, color }) => (
<MaterialCommunityIcons size={size} name="home" color={color} />
),
}}
/>
<Tab.Screen
name="ListingEdit"
component={ListingEditscreen}
options={{
tabBarIcon: ({ size }) => (
<MaterialCommunityIcons
size={40}
name="plus-circle"
color={"white"}
/>
),
tabBarIconStyle: styles.plusIcon,
}}
/>
<Tab.Screen
name="Account"
component={AccoutNavigator}
options={{
tabBarIcon: ({ size, color }) => (
<MaterialCommunityIcons
size={size}
name="account"
color={color}
/>
),
}}
/>
</Tab.Navigator>
</View>
);
}
const styles = StyleSheet.create({
plusIcon: {
backgroundColor: "tomato",
width: 70,
height: 70,
borderRadius: 35,
bottom: 30,
},
});
async function registerForPushNotificationsAsync() {
let token;
if (Platform.OS === "android") {
await Notifications.setNotificationChannelAsync("default", {
name: "default",
importance: Notifications.AndroidImportance.MAX,
});
}
if (Device.isDevice) {
const { status: existingStatus } =
await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== "granted") {
alert("Failed to get push token for push notification!");
return null;
}
// Get the Expo push token
token = (await Notifications.getExpoPushTokenAsync()).data;
} else {
alert("Must use physical device for Push Notifications");
}
return token;
}
- i need to get the token but i get that error