expo-notifications scheduleNotification is not working as expected in devices
See original GitHub issueđ Bug Report
Summary of Issue
Im im trying to schedule a repeat notification on everyday morning 9AM & night 9PM everyday. One Everytime use user opens app, im cancelling all old notifications & scheduling new one, (tried with checking scheduled notification, if not exist schedule new). This seems to be working fine in android simulator, when i install app in phone it triggers notification very rarely or some times nothing for a week. I have just followed given documentation for repeat local notifications. Need helpâŚ
Environment - output of expo diagnostics
& the platform(s) youâre targeting
Expo CLI 3.27.14 environment info:
System:
OS: macOS 10.15.7
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.3 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 23, 28, 29
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0
System Images: android-26 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 11.7/11E801a - /usr/bin/xcodebuild
npmPackages:
expo: ^39.0.0 => 39.0.2
react: 16.13.1 => 16.13.1
react-dom: 16.13.1 => 16.13.1
react-native: 0.63.2 => 0.63.2
react-native-web: ~0.13.7 => 0.13.13
npmGlobalPackages:
expo-cli: 3.27.14
Expo Workflow: bare
Reproducible Demo
const scheduleNotifications = async () =>{
// Cancel All notifications
await Notifications.cancelAllScheduledNotificationsAsync();
//9AM notification
await Notifications.scheduleNotificationAsync({
identifier: 'morning-1',
content: {
title: `Good Morning!`,
subtitle: 'Greetings',
body: `Have a great day`,
sound: true,
color: "#ffffff",
data: {
to: 'new-log'
}
},
trigger: {
hour: 9,
minute: 0,
repeats: true
}
});
//9PM notification
await Notifications.scheduleNotificationAsync({
identifier: 'night-notification',
content: {
title: `Good Night :)`,
subtitle: 'Have a great sleep :D',
body: `Have a great sleep :D`,
sound: true,
data: {
to: 'new-log'
},
color: "#000000" },
trigger: {
hour: 21,
minute: 0,
repeats: true
}
});
}
Steps to Reproduce
- Cancel all old notifications
- scheduling 2 daily notifications with triggers
trigger: {
hour: 9,
minute: 0,
repeats: true
}
&
trigger: {
hour: 21,
minute: 0,
repeats: true
}
- wait for thenotification
Expected Behavior vs Actual Behavior
Expected It should trigger 2 notifications every day, 1 on 9 AM & 1 on 9 PM Actual Triggering notifications regardless of trigger time & day, some tomes 3 days once, some day all 2 together at night, sometimes nothing for a week.
Issue Analytics
- State:
- Created 3 years ago
- Comments:24 (6 by maintainers)
Top Results From Across the Web
expo-notifications scheduleNotification is not working as ...
One Everytime use user opens app, im cancelling all old notifications & scheduling new one, (tried with checking scheduled notification, if not ......
Read more >Notifications - Expo Documentation
Schedule a notification repeating in some time interval (or a calendar date match on iOS),; Get and set application badge icon number,; Fetch...
Read more >Send notifications using expo-notifications(Part 1)
Local Notifications: They are scheduled, handle and triggered in the same device and are triggered inside the device.
Read more >[Solved]-Expo Local Notifications Not Scheduling-React Native
... import * as Notifications from 'expo-notifications'; Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldShowAlert: true, ...
Read more >Local Notifications using Expo - DEV Community â â
Note - Notifications do not work on an emulator, so make sure to use a Physical device. Step 1: Install Expo Notifications. First...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If someone is struggling with the same issue : for me the solution was to upgrade my expo SDK from 38 to 39. I think it is supposed to be working with 38 version but for some reason it doesnât. As soon as I upgraded it starts working like a charm.
Yep of course đ You can find bellow a simple component example to create a notification from what i did. I didnât try it but it should work, tell me if not :
First => donât forget to add this line in your app.json under the android object :
"useNextNotificationsApi": true,
Then : ` import * as Notifications from âexpo-notificationsâ; import * as Permissions from âexpo-permissionsâ;
`