【问题标题】:Push Notification Badges not Coming推送通知徽章不来
【发布时间】:2012-03-16 09:09:02
【问题描述】:

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

- (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];


}

【问题讨论】:

  • 您是否尝试过检查badgeValue 是否设置正确?
  • 你的服务器端代码呢?
  • 我的服务器有问题,我发现徽章值必须隐式设置为整数。
  • 它现在可以工作了,谢谢大家。

标签: iphone objective-c ios4 push-notification apple-push-notifications


【解决方案1】:

我的服务器端编码存在问题,因为我刚刚发现必须将徽章值隐式设置为整数才能获得所需的结果。

当我在徽章值中获得空值时。

【讨论】:

    【解决方案2】:

    我以前也遇到过这个问题,希望对你有帮助

    {"aps":{"alert":"dsfdsfsdfsdfsdfdfdfsdfsdf","badge":1,"sound":"a"}}
    

    确保徽章值上没有双引号

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 2010-12-28
      相关资源
      最近更新 更多