I've been busting my head against the table al morning with this. I know it's been asked before, but I really don't understand what's the problem with my code.
Here's the code I use to register and send interactive notifications.
Thanks in advance.
#define kNotificationActionNo @"ActionKeyNo"
#define kNotificationActionYes @"ActionKeyYes"
#define kNotificationCategoryVendingMachine @"VendingMachineNotification"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[self registerForNotification];
...
}
+ (void)sendLocalNotification:(NSString*)message info:(NSDictionary*)infoDict {
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = message;
localNotification.fireDate = [NSDate date];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.category = kNotificationCategoryVendingMachine;
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
- (void)registerForNotification {
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:NSLocalizedString(@"YES_LEGEND", nil)];
[action1 setIdentifier:kNotificationActionYes];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:NSLocalizedString(@"NO_LEGEND", nil)];
[action2 setIdentifier:kNotificationActionNo];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:kNotificationCategoryVendingMachine];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}