Repeating an iOS local notification

Source: Internet
Author: User
ArticleDirectory
    • Setting the repeat interval
    • Limitations
    • Example code

When I wrote about local communications one thing that I left out was the ability to scheduleRepeating notification.
One of the reasons I did not bother to mention the ability to set
Repeat interval is that the function is very limited. At least it is
With iOS 4.1 At the time of writing. To show what can and can not be
Done I will modify the original sample app to include the ability to set
A repeat interval.

Setting the repeat interval

The modified UI for the sample app now looks as below. A segmented
Control has been added to allow a repeat schedule to specified.
Possible options are to repeat every minute, hourly, daily or weekly. If
You think this is a limited set of options you will see that this not
Only down to my limited UI design skills but also because the possible
Options supported by local communications are limited.

Other than modifying the XIB file the code changes to implement
Repeat interval are minor. The method that creates the local
Notification (schedulenotification) has the following additional lines:

NsintegerIndex = [Schedulecontrol Selectedsegmentindex];
 
Switch(Index ){
 
Case 1:
 
Notif.Repeatinterval=Nsminutecalendarunit;
 
Break;
 
Case 2:
Notif.Repeatinterval=Nshourcalendarunit;
 
Break;
 
Case 3:
 
Notif.Repeatinterval=Nsdaycalendarunit;
 
Break;
 
Case 4:
Notif.Repeatinterval=Nsweekcalendarunit;
 
Break;
 
Default:
 
Notif.Repeatinterval=0;
 
Break;
 
}

 

The local notification object, which is of Type uilocalnotification
Has a property named repeatinterval which determines the repeat interval
For the delivery of the notification. The apple documentation does not
Really provide much in the way of explanation or example but
Repeatinterval is of Type nscalendarunit which if you check
Definition can take one of the following values:

    • Nseracalendarunit
    • Nsyearcalendarunit
    • Nsmonthcalendarunit
    • Nsdaycalendarunit
    • Nshourcalendarunit
    • Nsminutecalendarunit
    • Nssecondcalendarunit
    • Nsweekcalendarunit
    • Nsweekdaycalendarunit
    • Nsweekdayordinalcalendarunit
    • Nsquartercalendarunit

These are mostly self explanatory. If you set the repeatinterval
Nsdaycalendarunit then the notification will repeat every day at
Same time as the initial notification. The definition of intervals such
As week, month, quarter, etc. Is actually dependent on the calendar
Used. You can specify a different calendar from the current calendar
Setting the repeatcalendar property to an alternate nscalendar object.
In practice I am not sure you will ever find a practical reason to set
An alternate calendar.

Limitations

The main limitation of limits is that the user interface does not provide any wayCancel a repeating notification.
So if you create a local notification with an hourly repeat interval it
Will repeat every hour until the user launches your app and gives you
The chance to cancel it programatically. Note that the notification
Repeats even if the user selects the close/cancel button in
Notification alert dialog.

The other obvious limitation is that you can only use one of
Nscalendarunit repeat intervals. so you can have a repeat interval
One minute or one hour or one day but not five minutes or three hours or
Two days.

All things considered the ability to set a repeat interval for
Local notification is of very limited use as currently implemented. In
General I wocould say the handling of communications is an area where Apple
Cocould make substantial improvements in a future release of IOS.
Enhancing the UI to allow the user to view multiple notifications and
Snooze or cancel a repeating notification wocould make the feature much
More useful. It is interesting to note that the apple clock app has
Ability to snooze an alarm but there is no obvious way to create
Similar application with the current version of the Public IOS
Frameworks.

Example code

Not much has changed but you can get the updated xcode project for the example app here.

Http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.