Please provide the following:
- SDK Version: 39.0.2
- Platforms(Android/iOS/web/all): Android
Hey guys. I wanted to implement Push Notifications in my app. So the first thing to do initially is grant permissions. So I am asking for permissions with my useeffect hook by calling this function. Also I am using typescript.
async function registerForPushNotificationsAsync() {
let token;
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== "granted") {
alert('Failed to get push token for push notification!');
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
console.log(token);
} else {
alert('Must use physical device for Push Notifications');
}
if (Platform.OS === "android") {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
return token;
}
So far so good. The imports on the top are like this:
import * as Permissions from "expo-permissions";
import {Notifications} from "expo";
When I try to run the app on my android device (no emulator) I am getting the unhandled Promise rejection warning because Permissions.getAsync()
returns undefined.
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_expoNotifications.default.getExpoPushTokenAsync')]
What I’ve done:
- purged node_modules and installed new
- I switched from
import Permissions from "expo-permissions"
toimport * as Permissions from "expo-permissions"
- I cleared cache with
expo r -c
Edit: What I am now seeing, that the error-message from above is not the original one, so I think maybe there is also something wrong with the notification import or something. I dont know.