Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the repeat UILocal Notifications on the select list of Weekdays

I have implemented UILocal Notification using the following link

http://useyourloaf.com/blog/2010/07/31/adding-local-notifications-with-ios-4.html

And i have modified it to set the repet Notifications on each day by using

//To set the repeat notification
            notif.repeatInterval = NSDayCalendarUnit;

For exampke ex Every day at 10.00 AM

But my requirement is user needsto set the notification on selected Week Days (Monday to saturDay)

why because user may have weekly holidays like (SaturDay and Sunday) / Friday - Sunday) / Some other days..

on the week offs he shouldn't fire the notifications.

So we felicitate user to set the selected Working days and the notifications will set on those days only.. once user set the notifications.

For ex:

we have list of weekday Sun, MOn, Tue, Wed, Thu, Fri, Saturday

on those user selects Monday, Tuesday,WednesDay, Thursday. and set at 10Am

Then the notification will fire on every day 10.AM of these days.

How to do it

like image 597
iOS dev Avatar asked Mar 11 '13 15:03

iOS dev


People also ask

How do I send a local alert with a repeat interval?

In models, we need to create the below class with Title, Body, ID, IconId and NotifyTime. It will be useful to pass a local notification data to BroadcastReceiver receiver for repeating in Android. Create a class LocalNotificationService and we need to implement LocalNotification and Cancel methods like below.

How do I schedule a local notification?

This example demonstrate about How to schedule local notification in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is local notification in iOS?

Local notifications reach users whether your app is running in the foreground or the background and require no external infrastructure to send, which is why they are aptly termed “local.” These notifications simply require that a user's device is on in order to be received.


1 Answers

The API for UILocalNotification is very limited in this regard - you'll have to manually schedule 4 events repeating weekly on the days that the user selects.

An example of scheduling a repeat timer for monday would look like this

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.weekday = 2; // sunday = 1 ... saturday = 7
dateComponents.hour    = 10;

UILocalNotification *notification = //...
notification.repeatInterval = NSWeekCalendarUnit;
notification.fireDate       = [calendar dateFromComponents:dateComponents];

The day numbers can be found in the NSDateComponents Class Reference

like image 141
Paul.s Avatar answered Sep 22 '22 02:09

Paul.s