Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

iphone - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...