用于远程和本地通知的iOS徽章

用于远程和本地通知的iOS徽章,ios,apple-push-notifications,uilocalnotification,badge,Ios,Apple Push Notifications,Uilocalnotification,Badge,我的应用程序接收推送和本地两种类型的通知,我不知道管理徽章号码的最佳方式是什么。在本地通知的情况下,每当我创建徽章计数器时,我都会增加徽章计数器,但在推送通知的情况下。。。如果我没记错的话,只有当用户通过点击警报或横幅启动应用程序,或者应用程序处于活动状态时,才会调用委托方法didReceiveMemoteNotify:。否则,徽章的值是从通知的有效负载中获取的,不是吗?所以考虑到收到的本地通知+远程通知,我如何始终拥有更新的徽章值 谢谢您在远程通知中得到如下响应 Connection OK s

我的应用程序接收推送和本地两种类型的通知,我不知道管理徽章号码的最佳方式是什么。在本地通知的情况下,每当我创建徽章计数器时,我都会增加徽章计数器,但在推送通知的情况下。。。如果我没记错的话,只有当用户通过点击警报或横幅启动应用程序,或者应用程序处于活动状态时,才会调用委托方法didReceiveMemoteNotify:。否则,徽章的值是从通知的有效负载中获取的,不是吗?所以考虑到收到的本地通知+远程通知,我如何始终拥有更新的徽章值


谢谢

您在远程通知中得到如下响应

Connection OK sending message :{"aps":{"alert":"pushnotification testing","content-available":"","badge":"1","sound":"default"}} 134
在AppDelegte.h类中

取一个整数变量int i=0

//收到通知

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running

    app.applicationIconBadgeNumber=i++;
    NSLog(@"Recieved Notification %@",notif);
}

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

#if !TARGET_IPHONE_SIMULATOR
    NSString *badge = [apsInfo objectForKey:@"badge"];
    NSLog(@"Received Push Badge: %@", badge);

    // set it to Zero will clear it.
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

#endif
}

-(void) pw_setApplicationIconBadgeNumber:(NSInteger) badgeNumber
{
    [UIApplication sharedApplication].applicationIconBadgeNumber +=badgeNumber;
}
//当应用程序处于活动状态时,将徽章设置为零

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    application.applicationIconBadgeNumber =nil;

}
谢谢pw_setApplicationBadgeNumber:是一种与Pushwoosh一起使用的方法,对吗?我没有用它。我发现的问题是,我的应用程序显示推送通知和本地通知,即使我的服务器跟踪它需要发送的推送通知的徽章编号,我也不知道如何添加当前启动的本地通知的编号。。。
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    application.applicationIconBadgeNumber =nil;

}