Permissions Deprecated- React Native

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 Permissions from “expo-permissions”;

import AccountNavigator from “./AccountNavigator”;
import FeedNavigator from “./FeedNavigator”;
import ListingEditScreen from “…/screens/ListingEditScreen”;
import NewListingButton from “./NewListingButton”;
import routes from “./routes”;

const Tab = createBottomTabNavigator();

const AppNavigator = () => {
useEffect(() => {
registerForPushNotifications();
},[2]);
const registerForPushNotifications = async () => {
try {
const permission = await Permissions.askAsync(Permissions.NOTIFICATIONS);
if(!permission.granted) return;

  const token = await Notifications.getExpoPushTokenAsync();
  console.log(token);
  
} catch (error) {
  console.log("Error getting a push token", error);
  
}

}

Hello,

Yes.

instead of using :
import * as Permissions from “expo-permissions”;
const permission = await Permissions.askAsync(Permissions.NOTIFICATIONS);

we use:

through out the course, I’ve found 3 places from using “permissions”:

  1. ImageInput component
    import * as ImagePicker from “expo-image-picker”;
    const { granted } = await ImagePicker.requestCameraPermissionsAsync();

  2. useLocation hook
    import * as Location from “expo-location”;
    const { granted } = await Location.requestForegroundPermissionsAsync();

  3. useNotification hook
    import * as Notifications from “expo-notifications”;
    const permission = await Notifications.getPermissionsAsync();

I hope this hope you understand what this sentence means:
"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. "

cheers

1 Like

Here is the code fragment that works both for getting the permissions and the push token without getting the deprecation notice:

import * as Notifications from 'expo-notifications';

import ListingEditScreen from "../screens/ListingEditScreen";
import FeedNavigator from "./FeedNavigator";
import AccountNavigator from "./AccountNavigator"; 


const Tab = createBottomTabNavigator();

const AppNavigator = () => {

    useEffect(() => {
        registerForPushNotifications();
    }, []);

    const registerForPushNotifications = async () => {
        try {
            const permission = await Notifications.requestPermissionsAsync();
            if(!permission.granted) return;

            const token = (await Notifications.getExpoPushTokenAsync()).data;
            console.log(token);
        }
        catch (error){
            console.log('Error getting a push token ', error);
        }
    }
4 Likes

thanks @combyses , I was using the wrong method for asking permission.