这是我为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;
}
当我删除应用并再次安装时,会出现2个操作按钮(当我拉下通知横幅,或在通知中心向左滑动时)。但过了一段时间(我不确定是什么导致它),虽然我一直发送相同的通知,但它们仍然停止出现。这是我的通知内容:
{"aps":{"alert":"test","category":"coride_invite"},"journey_id":100}
请问有人可以解决一些问题吗?感谢
答案 0 :(得分:1)
如果代码中还有其他地方,请检查以下内容:
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
因为,UIUserNotificationSettings
是单身,无论何时调用它,它都会覆盖旧设置。因此,如果在没有任何按钮的情况下注册新设置,则不会显示任何按钮。
此处说明了更好的注册新设置的方法: Interactive push notifications - Hide/Show buttons