ios 8交互式通知未显示操作

这是我为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} 

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

如果它在其他任何地方,请检查代码中的以下内容:

  [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 

由于UIUserNotificationSettings是单例,因此无论何时调用它,它都会覆盖旧设置。 因此,如果在没有任何按钮的情况下注册新设置,则不会显示任何按钮。

这里解释了更好的注册新设置的方法: 交互式推送通知 – 隐藏/显示按钮