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

编程入门 行业动态 更新时间:2024-10-26 13:29:02
本文介绍了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交互式通知未显示操作

本文发布于:2023-06-06 05:55:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/534742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   通知   ios

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!