ios 8交互式通知未显示操作 [英] ios 8 interactive notifications not showing actions

查看:113
本文介绍了ios 8交互式通知未显示操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我为ios8注册交互式通知的代码:

This is my code to register Interactive 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 is : when i delete the app and install again, the 2 action buttons (when I pull down the notification banner, or swipe left in notification center) appears. But after a while ( i'm not really sure what cause it ), they stop appearing although i keep sending the same notification. This is my notification content:

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

有人可以解决一些问题吗?谢谢

Can anyone shed some light please ? Thanks

推荐答案

如果代码中还有其他地方,请检查以下代码:

Check for the following in you code if it is anywhere else as well:

 [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

因为, UIUserNotificationSettings 是单身,无论何时你这个叫它,它会覆盖旧的设置。因此,如果在没有任何按钮的情况下注册新设置,则不会显示任何按钮。

Since, UIUserNotificationSettings is singleton, whenever you call this, it overwrites the old settings. So if new settings is registered without any buttons it will not show any buttons.

此处说明了更好的注册新设置的方法:
交互式推送通知 - 隐藏/显示按钮

Better way of registering new setting is explained here: Interactive push notifications - Hide/Show buttons

这篇关于ios 8交互式通知未显示操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆