- Home /
How to send local notification same hour everyday on Android ans iOS?
I have managed to send local notifications like this
AndroidNotificationChannel notificationChannel = new AndroidNotificationChannel()
{
Id = "channel_id",
Name = "Default Channel",
Importance = Importance.High,
Description = "Generic notifications",
};
AndroidNotificationCenter.RegisterNotificationChannel(notificationChannel);
AndroidNotification notification = new AndroidNotification
{
Title = "SomeTitle",
Text = "SomeText",
FireTime = DateTime.Now.AddSeconds(15),
IntentData = "{\"title\": \"Notification 1\", \"data\": \"200\"}",
ShouldAutoCancel = true
};
AndroidNotificationCenter.SendNotification(notification, "channel_id");
But I need to send local notification at the same time every day on both Android and iOS. Like at 10 am. Is it possible? If yes can you help me how to achieve this?
Answer by Hellium · Oct 28, 2020 at 10:18 AM
The AndroidNotification
class seems to have a repeat interval
CODE NOT TESTED
DateTime now = DateTime.Now;
AndroidNotification notification = new AndroidNotification
{
Title = "SomeTitle",
Text = "SomeText",
FireTime = new DateTime(now.Year, now.Month, now.Day, 10, 0, 0).AddDays(1),
RepeatInterval = new TimeSpan(1, 0, 0, 0),
IntentData = "{\"title\": \"Notification 1\", \"data\": \"200\"}",
ShouldAutoCancel = true
};
Don't forget to remove the notifications when the user starts the game and schedule the notifications when he/she leaves
UPDATE further to investigations & tests.
The version of the Mobile Notification package must be greater or equal to 1.0.4 for the RepeatInterval to work. Right now (2020/10/28), the 1.0.4 version is in preview.
I've tested RepeatInterval. But looks like not working correctly. Setted Timespan to 1 $$anonymous$$ute
RepeatInterval = new TimeSpan(0, 1, 0)
Device Xiaomi $$anonymous$$i A2. OS is Android One
The documentation says
Remarks There is a $$anonymous$$imum period of 1 $$anonymous$$ute for repeating notifications.
Have you tried increasing the delay?
Your answer
Follow this Question
Related Questions
Reading notifications from Unity or knowing if notifications are enabled 0 Answers
Create notification if already there is no notification created 0 Answers
How to put a permanent notification on phone? 0 Answers
how to open app from notification intent 0 Answers
Facebook SDK notifications not working 2 Answers