繁体   English   中英

收到推送通知时如何设置徽章图标

[英]How to set badge icon when push notification is received

我工作在iOS聊天应用程序是在一个UIWebView 我还实现了推送通知。 但是我想知道如何检测设备上是否已收到聊天消息(推送通知),并能够相应地设置徽章图标。

使用parse.com(“推送通知”的默认设置),您可以通过将“徽章”键设置为所需的任何数字来“发送徽章”。 然后,接收端的操作系统将为您设置徽章编号。 见下文:

    PFPush *push = [[PFPush alloc] init];
    NSString *userChannel = [NSString stringWithFormat:@"USER-%@", userId];
    [push setChannel:userChannel];
    NSDictionary *data = @{@"alert":@"You have a new review!",@"badge":@1, @"sound":@"default"};
    [push setData:data];
    [push sendPushInBackground];

从iOS 8开始,请注意,如果希望接收方在接收到推送通知时听到提示音,则还必须包括“声音”键。

在接收端,用户打开应用程序后,您可能希望清除徽章图标。 您可以按照以下步骤进行操作:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    [PFPush handlePush:userInfo];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM