- SDK Version: 43
- Platforms(Android/iOS/web/all): Android
- Notifications
Documentation on “Local” notifications is non existent either, there’s a section at the top of the ‘expo-notifications’ docs just saying that it is supported.
I am not register a device token as these notifications are all created on the app - maybe I am missing something where you still need to provide a token…
Runs the notifications on the emulator, without any issues. All the code just works until I bundle and try to release the bundle or run an APK on the physical device(Pixel 6)
It’s not the device, because when I run this using npx react-native android
with metro
… also triggers the notifications on the physical device just fine.
Android permissions in manifest:
2 <uses-permission android:name="android.permission.INTERNET"/>
3 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
4 <uses-permission android:name="android.permission.VIBRATE"/>
5 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
6 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
7 <uses-permission android:name="android.permission.READ_CALENDAR" />
8 <uses-permission android:name="android.permission.WRITE_CALENDAR" />
9 <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
Code:
78 try {
79 await registerForPushNotificationsAsync()
80
81 const genericRepeatingNotificationsTrigger = {
82 hour: 21, minute: 4, repeats: true
83 }
84
85 const s = await Notifications.scheduleNotificationAsync({
86 content: {
87 channelId: 'default',
88 title: "How did you start your day?",
89 body: "Check in your progress while it's fresh! 💪",
90 Notifications.AndroidNotificationPriority.HIGH,
91 data: {screen: "SevenDayProgrammeScreen"},
92 },
93 trigger: genericRepeatingNotificationsTrigger
94 });
95
96
97 } catch(e) {
98 Alert.alert(`ERROR SETTING UP NOTIFICATIONS: ${JSON.stringify(e)}`)
}
67 export async function registerForPushNotificationsAsync() {
68 try {
69 let token;
70 if (Constants.isDevice) {
71 const { status: existingStatus } = await Notifications.getPermissionsAsync();
72 let finalStatus = existingStatus;
73 if (existingStatus !== 'granted') {
74 const { status } = await Notifications.requestPermissionsAsync();
75 finalStatus = status;
76 }
77 if (finalStatus !== 'granted') {
78 alert('Failed to get push token for push notification!');
79 return;
80 }
81 // Don't need token because you are running Local notifications
82 // token = (await Notifications.getExpoPushTokenAsync()).data;
83 // if (token) {
84 // console.log(token.data)
85 // }
86 } else {
87 alert('Must use physical device for Push Notifications');
88 }
89
90 if (Platform.OS === 'android') {
91 Notifications.setNotificationChannelAsync('default', {
92 name: 'default',
93 importance: Notifications.AndroidImportance.MAX,
94 vibrationPattern: [0, 250, 250, 250],
95 lightColor: '#FF231F7C',
96 });
97 }
98
99 return token;
100 } catch(e) {console.log(`ERROR_REGISTERING_USER_FOR_PUSH_NOTIFICATIONS ${e}`)}
101 }
Permissions are clearly registered and so is ‘default’ channel so the code is running on the app - no problem.