My app receives push notifications when an RSS feed in my app is updated. When the app is launched from the notification, that RSS feed opens. When the app is in the foreground, an alert view is shown. If the app is not in the foreground and is not opened from the notification, a badge icon appears on the menu table view in the cell to open that RSS feed. When the cell is selected the app badge icon is reset and the icon in the cell is removed.
I'm planning on adding notifications for things other than the RSS feed, such as member benefits, but I'm having trouble with showing the badge icon in the table view. My notificationType string is always null so there is never a badge icon placed in any cell in the menu table view.
In cellForRowAtIndexPath: in my menu table view.
I'm planning on adding notifications for things other than the RSS feed, such as member benefits, but I'm having trouble with showing the badge icon in the table view. My notificationType string is always null so there is never a badge icon placed in any cell in the menu table view.
Code:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UA_LINFO(@"Received remote notification: %@", userInfo);
[[UAPush shared]appReceivedRemoteNotification:userInfo applicationState:application.applicationState];
if (application.applicationState == UIApplicationStateActive) {
[[UAPush shared] resetBadge];
}
if (application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground) {
NSDictionary *apsInfo = [userInfo valueForKey:@"aps"];
if ([apsInfo valueForKey:@"alert"] != NULL) {
self.alert = [apsInfo valueForKey:@"alert"];
if ([self.alert containsString:@"ACTION ALERT"]) {
self.notificationType = @"action alert";
}
else if ([self.alert containsString:@"MEMBER BENEFIT"]) {
self.notificationType = @"member benefit";
}
}
}
}
In cellForRowAtIndexPath: in my menu table view.
Code:
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
badgeNumber = [NSString stringWithFormat:@"%ld", (long)[[UIApplication sharedApplication]applicationIconBadgeNumber]];
actionAlertBadge = [JSCustomBadge customBadgeWithString:badgeNumber withStringColor:[UIColor whiteColor] withInsetColor:[UIColor redColor] withBadgeFrame:NO withBadgeFrameColor:[UIColor redColor] withScale:1.0 withShining:NO withShadow:NO];
actionAlertBadge.frame = CGRectMake(83, 6, 30, 30);
if ([badgeNumber isEqualToString:@"0"]) {
actionAlertBadge.hidden = YES;
}
if (actionAlertBadge.hidden == NO) {
if ([appDelegate.notificationType isEqualToString:@"action alert"]) {
if (indexPath.section == 0) {
if (indexPath.row == 0) {
cell.accessoryView = actionAlertBadge;
}
}
}
else if ([appDelegate.notificationType isEqualToString:@"member benefit"]) {
if (indexPath.section == 0) {
if (indexPath.row == 5) {
cell.accessoryView = actionAlertBadge;
}
}
}
}