Ios 8 interactive notifications showing no action

This is my code for registering live notifications for ios8:

+ (void)registerInteractiveNotifications
{
    UIMutableUserNotificationCategory *corideInviteCategory = [self corideInviteCategory];
    UIMutableUserNotificationCategory *riderInviteCategory = [self riderInviteCategory];

    NSSet *categories = [NSSet setWithObjects:corideInviteCategory, riderInviteCategory, nil];
    UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                    UIUserNotificationTypeSound|
                                    UIUserNotificationTypeBadge);

    UIUserNotificationSettings *settings;
    settings = [UIUserNotificationSettings settingsForTypes:types
                                                 categories:categories];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}

+ (UIMutableUserNotificationCategory *)riderInviteCategory
{
    UIMutableUserNotificationAction *accept;
    accept = [[UIMutableUserNotificationAction alloc] init];
    [accept setActivationMode:UIUserNotificationActivationModeForeground];
    [accept setTitle:@"Accept"];
    [accept setIdentifier:RiderInviteAccept];
    [accept setDestructive:NO];
    [accept setAuthenticationRequired:NO];

    UIMutableUserNotificationAction *decline;
    decline = [[UIMutableUserNotificationAction alloc] init];
    [decline setActivationMode:UIUserNotificationActivationModeForeground];
    [decline setTitle:@"Decline"];
    [decline setIdentifier:RiderInviteDecline];
    [decline setDestructive:YES];
    [decline setAuthenticationRequired:NO];

    UIMutableUserNotificationCategory *actionCategory;
    actionCategory = [[UIMutableUserNotificationCategory alloc] init];
    [actionCategory setIdentifier:RiderInviteCategory];
    [actionCategory setActions:@[decline, accept]
                    forContext:UIUserNotificationActionContextDefault];
    [actionCategory setActions:@[decline, accept] forContext:UIUserNotificationActionContextMinimal];

    return actionCategory;
}

+ (UIMutableUserNotificationCategory *)corideInviteCategory
{
    UIMutableUserNotificationAction *accept;
    accept = [[UIMutableUserNotificationAction alloc] init];
    [accept setActivationMode:UIUserNotificationActivationModeForeground];
    [accept setTitle:@"Accept"];
    [accept setIdentifier:CorideInviteAccept];
    [accept setDestructive:NO];
    [accept setAuthenticationRequired:NO];

    UIMutableUserNotificationAction *decline;
    decline = [[UIMutableUserNotificationAction alloc] init];
    [decline setActivationMode:UIUserNotificationActivationModeForeground];
    [decline setTitle:@"Decline"];
    [decline setIdentifier:CorideInviteDecline];
    [decline setDestructive:YES];
    [decline setAuthenticationRequired:NO];

    UIMutableUserNotificationCategory *actionCategory;
    actionCategory = [[UIMutableUserNotificationCategory alloc] init];
    [actionCategory setIdentifier:CorideInviteCategory];
    [actionCategory setActions:@[decline, accept]
                    forContext:UIUserNotificationActionContextDefault];
    [actionCategory setActions:@[decline, accept] forContext:UIUserNotificationActionContextMinimal];

    return actionCategory;
}

      

What Happens: When I uninstall the app and reinstall it again, 2 action buttons appear (when I pull down the notification banner or swipe left in the notification center). But after a while (I'm not quite sure what the reason is) they stop showing up, although I keep sending the same notification. This is my notice:

{"aps":{"alert":"test","category":"coride_invite"},"journey_id":100}

      

Can anyone shed some light? Thanks to

+2


source to share


1 answer


Check if your code contains the following:

 [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

      



Since it UIUserNotificationSettings

is a singleton, whenever you call this, it overwrites the old settings. Therefore, if new settings are registered without any buttons, the buttons will not be displayed.

The best way to register new settings is explained here: Interactive push notifications - Hide / Show buttons

+1


source







All Articles