Notification is a very common information-transmitting mechanism in smartphone applications, and it can save resources without consuming resources to constantly check information status (pooling), which is divided into two different notification types, local and remote, under iOS. The local notification is managed by iOS under Notificationmanager, and only a packaged local notification object can be added to the system Notification management queue. The system will trigger the local notification at the specified time, and the whole notification process can be completed by applying the method of designing and handling the notification.
The object used by the local notification is the Uilocalnotification,uilocalnotification property that covers all the content needed to handle notification. The properties of Uilocalnotification are Firedate, TimeZone, Repeatinterval, Repeatcalendar, Alertbody, Alertaction, HasAction, Alertlaunchimage, Applicationiconbadgenumber, Soundname and UserInfo.
Scheduling of Uilocalnotification
Where Firedate, TimeZone, Repeatinterval and Repeatcalendar are used for uilocalnotification scheduling. Firedate is the exact time of Uilocalnotification's excitation. TimeZone is uilocalnotification whether the excitation time changes according to time zone changes, and if set to nil, then Uilocalnotification will be fired for a time, rather than an exact time to be fired. Repeatinterval is the time difference between uilocalnotification being repeatedly fired, but the time difference is based entirely on the calendar unit (nscalendarunit), such as the unit that fires each week, Nsweekcalendarunit, If not set, the excitation will not be repeated. Repeatcalendar is the calendar unit that the uilocalnotification uses to repeat fires, and if not, the system default calendar will be used as a reference calendar. Uilocalnotification's alert content
Alertbody, Alertaction, Hasaction, and alertlaunchimage are processed when the application is not running
Uilocalnotification reminders are required content. Alertbody is a string of realistic reminders (nsstring) that, if Alertbody is not set, will not be alerted when the notification is fired. Alertaction is also a string of characters (NSString), and the alertaction content will be used as the text on the action button in the reminder, and if not set, the action button in the reminder message will appear as "View" relative to the text form. Alertlaunchimage is when the user clicks the action button ("View") in the Reminder box, waiting for the picture to be displayed when the application loads, which replaces the loaded picture that was originally set. Hasaction is a Boolean value that controls whether the action button is displayed in a reminder box, and the default value is yes.
other parts of the uilocalnotification
Applicationiconbadgenumber, Soundname and UserInfo will make uilocalnotification more complete. Applicationiconbadgenumber is the number displayed in the upper-right corner of the application icon, which gives the user a direct understanding of the notification that the application needs to handle. Soundname is another uilocalnotification used to remind users that when notification is fired, the sound is played to remind the user that there is a notification to deal with, and if you don't set Soundname, Notification is excited that there will be no sound playback, except for the application of a specially crafted sound, you can also set the Soundname to Uilocalnotificationdefaultsoundname to use the system default reminder sound. UserInfo is the nsdictionary that notification uses to pass data.
Register Uilocalnotification
After the Uilocalnotification object is set, the application needs to register the Uilocalnotification object that has been set up in the System notification processing queue. The manner of registering uilocalnotification * localnotification is:
[[UIApplication sharedapplication] schedulelocalnotification:localnotification];
In some cases, the application may need to directly inspire a notification rather than wait for a while to trigger, the application can be triggered directly in the following way the set of notification:
[[UIApplication sharedapplication] presentlocalnotificationnow:localnotification]; Handling Uilocalnotification
When the Reminder Box action button is clicked, the application starts running and can be handled in the-(BOOL) Application:didfinishlaunchingwithoptions: This application delegate method. You can load the most recently unhandled notification in the following ways:
Uilocalnotification * Localnotif=[launchoptions Objectforkey:uiapplicationlaunchoptionslocalnotificationkey];
If the application is running, you can process notification by overwriting the method-(void) application:didreceivelocalnotification in application delegate. As the second parameter of the method is the Uilocalnotification object, you only need to handle the userinfo that the object carries to handle the response action. Cancel Uilocalnotification
You can use the following two ways to cancel a registered notification, the first way you can directly cancel a specified notification, the second way will be the application of the registered notification canceled together
[[UIApplication sharedapplication] cancellocalnotification:localnotification];
[[UIApplication sharedapplication] cancelalllocalnotification]; Summary
The local notification mechanism is very effective in application development and can help developers manage some of the events that need to happen at specified times, such as the application of alarm clock classes. And because the system is unified for notification management, the same task can be handled very simply, without having to waste resources on the application to wait for the event to be triggered.
Turn from: http://hi.baidu.com/%CB%BC%C3%F4%D3%EA/blog/item/173ee25032b4d301367abe8a.html