当我收到 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/