推送通知徽章不来 [英] Push Notification Badges not Coming
本文介绍了推送通知徽章不来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这个编码苹果推送通知,推送通知来了,但他们没有任何徽章即将到来,任何建议什么是错的这个code,那我没有得到徽章。我已经检查设置选项卡,徽章都在那里。
- (BOOL)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions {[UIApplication的sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];[UIApplication的sharedApplication] .applicationIconBadgeNumber = 0;} - (无效)应用:(*的UIApplication)应用didRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)deviceToken1 { * NSString的海峡= [的NSString
stringWithFormat:@%@,deviceToken1]
的NSLog(@%@,STR); self.deviceToken = [的NSString stringWithFormat:@%@,STR]
的NSLog(@开发---%@,self.deviceToken);
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@< withString:@];
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@withString:@];
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@>中withString:@];
的NSLog(@开发---%@,self.deviceToken);
} - (无效)应用:(*的UIApplication)应用didFailToRegisterForRemoteNotificationsWithError:(NSError *)错误{ * NSString的海峡= [的NSString stringWithFormat:@错误:%@,犯错]
的NSLog(@%@,STR);} - (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*){用户信息
的NSLog(@接到通知:%@,用户信息);
// [自addMessageFromRemoteNotification:用户信息]; * NSString的alertValue = [[USERINFO valueForKey:@APS] valueForKey:@徽章];
的NSLog(@我message--%@,alertValue);
INT badgeValue = [alertValue的intValue]; [UIApplication的sharedApplication] setApplicationIconBadgeNumber:badgeValue];
}
解决方案
有与我的服务器端编码一个问题,因为我刚刚发现,徽章值具有作为整数得到期望的结果被隐式设置。
因为我在徽章的价值越来越空值。
I am using this coding for apple push notification, push notifications are coming but they are coming without any badges, any suggestion what is wrong with this code, that I am not getting badges. I already check the setting tab, and badges are on there.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken1 {
NSString *str = [NSString
stringWithFormat:@"%@",deviceToken1];
NSLog(@"%@",str);
self.deviceToken = [NSString stringWithFormat:@"%@",str];
NSLog(@"dev --- %@",self.deviceToken);
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@"<" withString:@""];
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@" " withString:@""];
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@">" withString:@""];
NSLog(@"dev --- %@",self.deviceToken);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"%@",str);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Received notification: %@", userInfo);
//[self addMessageFromRemoteNotification:userInfo];
NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"];
NSLog(@"my message-- %@",alertValue);
int badgeValue= [alertValue intValue];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];
}
解决方案
There was a problem with my server side coding as I just find out that badge value has to be implicitly set as integer to get desired result.
As I'm getting null value in badge value.
这篇关于推送通知徽章不来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文