gpt4 book ai didi

iphone - 应用程序关闭时更新徽章图标

转载 作者:行者123 更新时间:2023-12-03 20:40:32 24 4
gpt4 key购买 nike

当我收到 PN 时,我正在尝试更新我的应用程序的徽章图标(已关闭)。

我尝试添加代码,但当我的应用程序关闭时它不起作用。当应用程序在前台运行时它会起作用。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

//Accept push notification when app is not open
if (remoteNotif) {
[application setApplicationIconBadgeNumber:100];
return YES;
}

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

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 30];

}

最佳答案

如果您的应用程序已关闭或在后台运行,则推送通知不会唤醒它。您需要在服务器端执行此操作,并在通知负载中包含您希望在图标上看到的数字:

{
"aps" : {
"alert" : "Your notification message",
"badge" : 1
}
}

查看 Push Notification programming guide 上的 Apple 文档

关于iphone - 应用程序关闭时更新徽章图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17781130/

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