How to Increment the Push notification Badge iPhone
Is it possible to increment the badge value on receiving the notification. OR Should I send the count as payload ?
If i am sending the badge value as "1" every time, how could i increment the badge-value in the icon of the app if the app is not open.
I used this code but doesn't work.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
}
If you want to change the icon badge automatically use the following code.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
application.applicationIconBadgeNumber = 0;
NSLog(@"userInfo %@",userInfo);
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
[application setApplicationIconBadgeNumber:[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue]];
NSLog(@"Badge %d",[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue]);
}
We also need to change the php file. So we can get the change the icon badge automatically
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'id' => '135',
'badge' => 8
);
Since push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.
But you can send the badge number in the payload of the push notification, but the you will have to do the calculation server side.
You should read :Local and Push Notification Programming Guide and specially the The Notification Payload.
The payload could look like this:
{ "aps" : { "alert" : "You got your emails.", "badge" : 9 } } Now the app application badge icon will show 9.
链接地址: http://www.djcxy.com/p/67260.html下一篇: 如何增加推送通知徽章iPhone