本文介绍了推送通知徽章没有来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此编码进行苹果推送通知,推送通知即将到来,但它们没有任何徽章,任何建议此代码有什么问题,我没有收到徽章.我已经检查了设置选项卡,那里有徽章.

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.

这篇关于推送通知徽章没有来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 15:04