I tried to program a local notification by expo, following the code provide on:
here – docs.expo.dev
The problem: the notification simple don’t appear in my phone – IOS. When I click into the button, nothing happens.
My App.js file:
import { StyleSheet, Button, View } from 'react-native';
import * as Notifications from 'expo-notifications';
Notifications.setNotificationHandler({
handleNotification: async () => {
return {
shouldPlaySound: false,
shouldSetBadge: false,
shouldShowAlert: true,
};
}
});
export default function App() {
function scheduleNotificationHandler() {
Notifications.scheduleNotificationAsync({
content: {
title: 'My first local notification',
body: 'This is the body of the notification.',
},
trigger: {
seconds: 5
}
});
}
return (
<View style={styles.container}>
<Button
title="Schedule Notification"
onPress={scheduleNotificationHandler}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Could anybody help me? Thanks for your attention.
I think the problem can be in the permissions of my device.
2
Answers
So, after some time of research, i find an answer for my problem...
I think the problem is with the permissions.
If you go to this link expo_page_notifications, there is a guide to do that.
This is the code: