Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Custom buttons not showing for interactive notification

I am currently working on interactive iOS notifications made ​​by 8 and honestly, I really struggle to see my buttons. With the code below, I fail to see my buttons:

//INTERACIVE

UIMutableUserNotificationAction *acceptAction =
[[UIMutableUserNotificationAction alloc] init];

acceptAction.identifier = @"ACCEPT_IDENTIFIER";
acceptAction.title = @"Accept";
acceptAction.activationMode = UIUserNotificationActivationModeBackground;
acceptAction.destructive = NO;
acceptAction.authenticationRequired = NO;

UIMutableUserNotificationAction *maybeAction =
[[UIMutableUserNotificationAction alloc] init];

maybeAction.identifier = @"MAYBE_IDENTIFIER";
maybeAction.title = @"Maybe";
maybeAction.activationMode = UIUserNotificationActivationModeBackground;
maybeAction.destructive = NO;
maybeAction.authenticationRequired = YES;


UIMutableUserNotificationAction *declineAction =
[[UIMutableUserNotificationAction alloc] init];

declineAction.identifier = @"DECLINE_IDENTIFIER";
declineAction.title = @"Decline";
declineAction.activationMode = UIUserNotificationActivationModeBackground;
declineAction.destructive = YES;
declineAction.authenticationRequired = NO;


UIMutableUserNotificationCategory *inviteCategory =
[[UIMutableUserNotificationCategory alloc] init];

inviteCategory.identifier = @"INVITE_CATEGORY";

[inviteCategory setActions:@[acceptAction, maybeAction, declineAction]
                forContext:UIUserNotificationActionContextDefault];

[inviteCategory setActions:@[acceptAction, declineAction]
                forContext:UIUserNotificationActionContextMinimal];


NSSet *categories = [NSSet setWithObjects:inviteCategory, nil];
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
localNotification.alertBody = @"Testing";
localNotification.category = @"INVITE_CATEGORY"; //  Same as category identifier
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

Any Idea for my problem? Despite all the examples on the Internet, I'm apparently the only one with this problem.

like image 265
NikLoy Avatar asked Dec 20 '22 10:12

NikLoy


1 Answers

There's a really great tutorial here: The Code Ninja

Everything in your code looks fine. I've gotta ask to make sure you're not just overlooking what actually happens - if you were looking at the notification on the home screen, did you swipe left on the notification to reveal the buttons?

Here is what I am using (sorry about the swift)

Initial Prompt for notifications

    var openAction = UIMutableUserNotificationAction()
    openAction.identifier = "OPEN_IDENTIFIER"
    openAction.title = "Open"
    openAction.destructive = false
    openAction.authenticationRequired = false
    openAction.activationMode = .Foreground

    var snoozeAction = UIMutableUserNotificationAction()
    snoozeAction.identifier = "SNOOZE_IDENTIFIER"
    snoozeAction.title = "Snooze"
    snoozeAction.destructive = true
    snoozeAction.authenticationRequired = false
    snoozeAction.activationMode = .Background

    var snoozeable = UIMutableUserNotificationCategory()
    snoozeable.identifier = NOTE_SNOOZE_CAT
    snoozeable.setActions([openAction, snoozeAction], forContext: .Default)
    snoozeable.setActions([openAction, snoozeAction], forContext: .Default)

    var notSnoozable = UIMutableUserNotificationCategory()
    notSnoozable.identifier = NOTE_NO_SNOOZE_CAT
    notSnoozable.setActions([openAction], forContext: .Default)
    notSnoozable.setActions([openAction], forContext: .Default)

    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Sound | .Alert |
        .Badge, categories: NSSet(array:[snoozeable, notSnoozable])
        ))

Local Notification

    var notification             = UILocalNotification()
    notification.fireDate        = fireDate
    notification.timeZone        = NSTimeZone.defaultTimeZone()
    notification.alertBody       = "Alert Body"
    notification.userInfo        = userInfo
    notification.category        = blnCanSnooze ? NOTE_SNOOZE_CAT : NOTE_NO_SNOOZE_CAT
    UIApplication.sharedApplication().scheduleLocalNotification(notification)
like image 82
Stephen Donnell Avatar answered Dec 24 '22 02:12

Stephen Donnell