UILocalNotification to execute an action
I would like to have a UILocalNotification to execute an action whenever it gets fired. What I really want to do is to update application.applicationIconBadgeNumber programmatically. Right now I do this whenever the user exits the applic开发者_运维技巧ation, the problem is that the badge number may have to change even if the user is not using the application. Is this possible?
You probably want to read Local and Push Notification Programming Guide. Especially this section. And finally read the UILocalNotification Class Reference, which include James' code.
To update the badge number of your app whilst the user isn't in the app, you can set the following property of the UILocalNotification instance:
@property(nonatomic) NSInteger applicationIconBadgeNumber
From the documentation:
The default value is 0, which means "no change.” The application should use this property’s value to increment the current icon badge number, if any.
You can't execute any code when the UILocalNotification fires, but you can (of course) execute code if the user decides to tap on the action button if you set one, as the user will be returned to your app.
精彩评论