推送通知徽章没有出现?

发布于 2024-12-12 06:00:43 字数 595 浏览 0 评论 0原文

我正在使用 Urban Airship 向我的应用程序发送推送通知

,例如:

{"aps": {"badge": 2, "alert": "Part 2 of the August Issue is ready to download!", "sound": "default"}, "device_tokens": ["X"]}

警报将完美显示,但是无论我将“badge”设置为什么,应用程序图标都不会带有标记:#...

我的有效负载是否不正确或者是否有额外的内容我应该添加到我的应用程序中来处理徽章和警报的代码?谢谢!

编辑: 我正在注册这样的推送通知:

// Register for notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];

I'm using Urban Airship to send push notifications to my app

eg:

{"aps": {"badge": 2, "alert": "Part 2 of the August Issue is ready to download!", "sound": "default"}, "device_tokens": ["X"]}

The alert will display perfectly, however the app icon is never badged regardless of what I set "badge":# to...

Is my payload incorrect or is there extra code I'm supposed to add to my app to handle badges as well as alerts? Thanks!

EDIT:
I'm registering for push notifications like this:

// Register for notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泛滥成性 2024-12-19 06:00:43

我正在运行类似的问题。检查了几分钟后。我注意到我的服务器端代码有问题。我发现徽章值必须隐式设置为整数才能获得所需的结果。希望对阅读本文的人有所帮助。

I was running with a similar problem. After a few minutes of checking around. I notice that there was a problem with my server side code. I found out that badge value has to be implicitly set as an integer to get the desired result. Hope that helps anyone reading this.

短暂陪伴 2024-12-19 06:00:43

在 appdelegate .m 文件中设置以下代码。

-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{


    NSLog(@"Received notification: %@", userInfo);
    //[self addMessageFromRemoteNotification:userInfo];

    NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"];
    NSLog(@"my message-- %@",alertValue);
    int badgeValue= [alertValue intValue];

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];

}

set the following code in the appdelegate .m file..

-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{


    NSLog(@"Received notification: %@", userInfo);
    //[self addMessageFromRemoteNotification:userInfo];

    NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"];
    NSLog(@"my message-- %@",alertValue);
    int badgeValue= [alertValue intValue];

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];

}
兔姬 2024-12-19 06:00:43

在iOS 5中有一个设置->通知。仔细检查徽章应用程序图标是否已打开。

我假设您测试时该应用程序不在前台?如果它位于前台,那么您必须手动处理徽章。

In iOS 5 there is a Settings -> Notifications. Double check that the Badge App Icon is turned on.

I assume that the app is not in the foreground when you were testing? It if is in the foreground then you have to handle badging manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文