SDK Version: 5.3.0
Platforms(Android/iOS/web/all): Android, iOS, web
I’m new to notifications with Expo so forgive me if I’ve overlooked a simple solution. I’m trying to get the code from the documentation to work: Push Notifications Overview - Expo Documentation. In Chrome, there aren’t any problems, but on mobile (both Android and iOs), Notifications is an empty object, so I can’t use Notifications.requestPermissionsAsync().
Any help would be greatly appreciated.
This is the code I’m trying to debug
import * as Device from "expo-device";
import * as Notifications from "expo-notifications";
import React, { useEffect } from "react";
import { Text, View } from "react-native";
export default function App() {
async function registerForPushNotificationsAsync() {
if (!Device.isDevice) {
alert("Must use a physical device for push notifications");
return null;
}
console.log(Notifications.requestPermissionsAsync);
try {
Notifications.requestPermissionsAsync()
.then((res) => {
const status = res.status;
if (status !== "granted") {
alert("failed to get push token");
return null;
}
})
.catch((err) => console.log("err", err));
} catch (err) {
alert(err);
}
}
useEffect(() => {
registerForPushNotificationsAsync();
}, []);
return (
<View
style={{
flex: 1,
alignItems: "center",
justifyContent: "space-around",
}}
>
<Text>Test</Text>
</View>
);
}