Oscar Del Ben
Oscar Del Ben

Reputation: 4515

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 application, the problem is that the badge number may have to change even if the user is not using the application. Is this possible?

Upvotes: 1

Views: 1529

Answers (2)

James Bedford
James Bedford

Reputation: 28962

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.

Upvotes: 0

Kyone
Kyone

Reputation: 523

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.

Upvotes: 1

Related Questions