徽章计数不为推notification.always徽章计数提高仍然为1? [英] Badge Count is not increasing for push notification.always badge count remains 1?
问题描述
我的应用程序徽章计数保持徽章算作1,如果我得到更多然后1通知还徽章计数仅remaing 1 。
下面是我的code
- (无效)应用:(*的UIApplication)的应用
didReceiveRemoteNotification:(NSDictionary的*){用户信息 * NSString的消息=零;
ID警报= [USERINFO objectForKey:@APS];
如果([警报isKindOfClass:[NSString类]){
消息=警报;
}
否则,如果([警报isKindOfClass:[NSDictionary的类]){
消息= [警报objectForKey:@警报];
}
如果(警告){
UIAlertView中* alertView = [[UIAlertView中页头] initWithTitle:@XYZ
消息:消息
委托:自我
cancelButtonTitle:@OK
otherButtonTitles:@取消,零]
alertView.tag = 2525;
[alertView秀]
}
}
- (无效)alertView:(UIAlertView中*)alertView
clickedButtonAtIndex:(NSInteger的)buttonIndex { 如果(alertView.tag == 2525){
[UIApplication的sharedApplication] .applicationIconBadgeNumber =
[UIApplication的sharedApplication] .applicationIconBadgeNumber-1;
}
}
您必须从服务器端做到这一点。在我来说,我已经通过PHP和MySQL做了。这里是我的数据库
我添加一个字段badgecount,我增加了徽章计数每次我发推送到设备与此code时间
$查询=选择badgecount FROM pushnotifications WHERE device_token ='{$ device_token}';
$查询= $这个 - > DB-GT&;查询($查询);
$行= $查询 - > row_array();
$ updatequery =更新pushnotifications设置badgecount = badgecount + 1 WHERE device_token ='{$ device_token}';
$ updatequery = $这个 - > DB-GT&;查询($ updatequery);
$设备= $ device_token;
$有效载荷['APS'] =阵列('警报'=> $ pushmessage,'徽章'=> $行[badgecount] + 1,'声音'= GT;'默认');
$有效载荷= json_en code($负载);
...
和我再拍的API使得badgcount 0,这是所谓的
- (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*)USERINFO
因此,当通知看出它再次为零是在服务器中。
My app badge count in not increasing when app is in background for push notifications.Count increase by 1 only for the first push notification and always remains badge count as 1, if i get more then 1 notification also badge count remaing 1 only. Below is my code
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSString *message = nil;
id alert = [userInfo objectForKey:@"aps"];
if ([alert isKindOfClass:[NSString class]]) {
message = alert;
}
else if ([alert isKindOfClass:[NSDictionary class]]) {
message = [alert objectForKey:@"alert"];
}
if (alert) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"xyz"
message:message
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
alertView.tag=2525;
[alertView show];
}
}
-(void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag==2525) {
[UIApplication sharedApplication].applicationIconBadgeNumber =
[UIApplication sharedApplication].applicationIconBadgeNumber-1;
}
}
You have to do it from the server side. In my case I have done it through php and mysql. Here is my database
I have added a field badgecount and i increase the badge count every time i send the push to the device with this code
$query = "SELECT badgecount FROM pushnotifications WHERE device_token = '{$device_token}'";
$query = $this->db->query($query);
$row = $query->row_array();
$updatequery = "update pushnotifications set badgecount=badgecount+1 WHERE device_token ='{$device_token}'";
$updatequery = $this->db->query($updatequery);
$device = $device_token;
$payload['aps'] = array('alert' => $pushmessage, 'badge' =>$row["badgecount"]+1, 'sound' => 'default');
$payload = json_encode($payload);
...
And I also make another api for making the badgcount 0 which is called in the
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
So when the notification is seen it is again zero in the server.
这篇关于徽章计数不为推notification.always徽章计数提高仍然为1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!