gpt4 book ai didi

ios - 角标(Badge)未在 iOS 8 中设置

转载 作者:行者123 更新时间:2023-11-28 18:57:59 25 4
gpt4 key购买 nike

尝试使用此代码通过远程通知设置角标(Badge)编号

UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);

UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[application setApplicationIconBadgeNumber:7];

..
}

但我没有在图标上看到角标(Badge)。

是否有我缺少的配置?

最佳答案

Badge: The number to display as the badge of the app icon. If this property is absent, the badge is not changed. To remove the badge, set the value of this property to 0.

您无需手动设置角标(Badge)。如 here 中所述它是根据您的有效载荷中的“角标(Badge)”自动管理它的有效载荷。并且是您在服务器端代码中管理有效载荷。

像这样:

     {
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}

此外,首先您必须向 iOS8 中的用户请求权限,例如 this在你的 -didFinishLaunchingWithOptions 委托(delegate)方法中

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

如果您的应用收到通知,然后您的应用将变为事件状态,您有责任像这样重置角标(Badge)编号:

- (void)applicationDidBecomeActive:(UIApplication *)application {

application.applicationIconBadgeNumber = 0;
}

这是另一个 reference引用如下:

The badge icon number is governed by the badge property in the payload received as push message. The app itself has no role to play in what number shows up till the app becomes active. Setting the 'badge' property to any integer value (Note : it should not be string and should NOT be enclosed within "") does what is needed. The OS on receiving the notification looks for the value for 'badge' and immediately sets it on the app badge icon. All this happens when app is not active. To make sure it increments or decrements based on what happens in the app, the app should send message to server with the updated badge number.

In the active state, it is app's responsibility to handle the remote notification and change the badge icon.

关于ios - 角标(Badge)未在 iOS 8 中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com