Push-Notification-Badge-Count Nicht Aktualisiert

dies ist mein code für apple push-Benachrichtigung, wenn die Anwendung ausgeführt wird, und die Benachrichtigung kommt, ich bin erhöht die Abzeichen zählen und erste gewünschte Ergebnis, wenn ich auf home-Taste auf app-Symbol. aber wenn ich nicht bin, läuft meine Anwendung und die Benachrichtigung kommt, es hat nicht die "auto increment" badge-count und bleibt nur 1. der Wert 1 kommt vom server. kann jeder ein Punkt, wo ich falsch mache. vielen Dank im Voraus.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    userMessageCounter = @"0";
    postType = 0;
    joinedStreamChecker = 0;
    OwnerValue = 0;
    pushValue = 1;
    badgeValue =0;

    //Override point for customization after application launch.

    //Add the navigation controller's view to the window and display.
    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];


    [[UIApplication sharedApplication] 
     registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeAlert | 
      UIRemoteNotificationTypeBadge | 
      UIRemoteNotificationTypeSound)];


    //[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
    //(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    //[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    if (types == UIRemoteNotificationTypeNone) 
    {
        pushValue = 0;


        NSLog(@"notification off");
    }

    return YES;
}


- (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);
    badgeValue= [alertValue intValue];
    [UIApplication sharedApplication].applicationIconBadgeNumber += badgeValue;
    //badgeValue = [UIApplication sharedApplication].applicationIconBadgeNumber;
    //[UIApplication sharedApplication].applicationIconBadgeNumber=0;
    //[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];


}
  • mögliche Duplikate von Push-Notification-Badges, die nicht Kommen
  • ich habe nicht die Antwort bekommen, deshalb habe ich die Frage gepostet hier.
  • Das ist nicht, wie es funktioniert. Bearbeiten Sie Ihre ursprüngliche Frage, oder fügen Sie eine bounty. Auf dem original eine, die Sie sagen, es funktioniert, eh?
  • ok, ich werde es tun, von nächsten mal danke.
  • Hier ist die Lösung für genau das gleiche problem stackoverflow.com/questions/26117430/...
Schreibe einen Kommentar