推送通知applicationIconBadgeNumber不ios7更新 [英] Push notification applicationIconBadgeNumber is not update in ios7
问题描述
我使用下面的应用程序委托code接收远程通知,但其applicationIconBadgeNumber(出现在红/白应用图标的左上角)未更新的应用程序时,在后台。当收到推送通知其出现在屏幕幻灯片动画的右上角,在通知有效载荷徽章计数正在添加完美形式的服务器端。
I am using following code in app delegate to receive Remote notification but its applicationIconBadgeNumber (appear on app icon's top left corner in red/white) is not updating when app in background. when push notification received its appear in top corner of screen with slide animation , in notification payload Badge count is comming form server side perfectly.
在 didFinishLaunchingWithOptions
我已经把下面code
In didFinishLaunchingWithOptions
I have put following code
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
远程通知代表:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *deviceTokenTrimmed = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
currentdeviceToken=deviceTokenTrimmed;
[[NSUserDefaults standardUserDefaults] setValue:deviceTokenTrimmed forKey:@"pushtoken"];
NSLog(@"Device Token didRegisterForRemoteNotificationsWithDeviceToken : %@",deviceTokenTrimmed);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Device Token in FailToRegister RemoteNotifications ERROR %@",error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"%@",userInfo);
if (application.applicationState == UIApplicationStateActive)
{
/***********code to show alert********/
if (![[[NSString alloc]initWithString:[[userInfo objectForKey:@"aps"] objectForKey: @"alert"]] isEqualToString:@""] && [[NSString alloc]initWithString:[[userInfo objectForKey:@"aps"] objectForKey: @"alert"]]!=nil) {
NSString *MSG =[[NSString alloc]initWithString:[[userInfo objectForKey:@"aps"] objectForKey: @"alert"]];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:MSG delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Notification Received." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
[alert show];
}
}else{
application.applicationIconBadgeNumber =[[[userInfo objectForKey:@"aps"] objectForKey: @"badge"]integerValue];
}
}
先谢谢了。
推荐答案
我发现溶胶,其实应用:didReceiveRemoteNotification不叫当后台应用程序,其操作系统负责更新applicationIconBadgeNumber当应用程序在后台,
在我的情况下,实际的问题是有效载荷。从服务端就被定为字符串,但它应该是整数。我张贴这是用PHP编写的有效载荷正确的code。
I found sol, Actually application:didReceiveRemoteNotification Not called when application in background, Its os responsibility to update applicationIconBadgeNumber when app in background, in my case actual problem was in payload. From Server End it was set as string but it should be integer. i am posting payload correct code which is written in php.
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'sound.caf',
'badge' => $badge_count // Should be int type
);
谢谢,mokujin和人士Himanshu
Thanks, mokujin and Himanshu
这篇关于推送通知applicationIconBadgeNumber不ios7更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!