这是我为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交互式通知未显示操作
发布评论