Vaibhav Jhaveri
Vaibhav Jhaveri

Reputation: 1605

iOS Interactive UILocalNotifications

I am trying to implement Interactive UILocalNotifications.

Following is my code. I am unable to get 3 Action Buttons of receiving Notification.

UIMutableUserNotificationAction *nAction1 = [[UIMutableUserNotificationAction alloc] init];
nAction1.identifier = @"Present";
nAction1.title = @"Present";
nAction1.activationMode = UIUserNotificationActivationModeBackground;
nAction1.destructive = NO;
nAction1.authenticationRequired = YES;

UIMutableUserNotificationAction *nAction2 = [[UIMutableUserNotificationAction alloc] init];
nAction2.identifier = @"Late";
nAction2.title = @"Late";
nAction2.activationMode = UIUserNotificationActivationModeBackground;
nAction2.destructive = NO;
nAction2.authenticationRequired = YES;

UIMutableUserNotificationAction *nAction3 = [[UIMutableUserNotificationAction alloc] init];
nAction3.identifier = @"Absent";
nAction3.title = @"Absent";
nAction3.activationMode = UIUserNotificationActivationModeBackground;
nAction3.destructive = YES;
nAction3.authenticationRequired = YES;

UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
notificationCategory.identifier = @"Attendance";
[notificationCategory setActions:@[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[nAction3, nAction1] forContext:UIUserNotificationActionContextDefault];

NSSet *categories = [NSSet setWithObjects:notificationCategory, nil];

UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:categories];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
localNotification.alertBody = @"Testing";
localNotification.category = @"Attendance";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

Upvotes: 0

Views: 131

Answers (1)

Andrea
Andrea

Reputation: 26385

[notificationCategory setActions:@[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[nAction3, nAction1] forContext:UIUserNotificationActionContextDefault];

It seems that you are overriding the same context with just 2 buttons I guess that the correct should be:

[notificationCategory setActions:@[nAction3, nAction2, nAction1] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[nAction3, nAction1] forContext:UIUserNotificationActionContextMinimal];

Upvotes: 1

Related Questions