Ios UITableView单元格中的通知标记

Ios UITableView单元格中的通知标记,ios,objective-c,uitableview,apple-push-notifications,Ios,Objective C,Uitableview,Apple Push Notifications,当前,我的应用程序接收有关RSS源更新的通知。如果用户从通知中打开应用程序,它将打开到正确的视图控制器。如果用户未确认通知并从应用程序图标打开应用程序,则当用户打开应用程序内的菜单时,该rss源的表视图单元格中会有一个带有applicationBadgeNumber的徽章图标。选择该行后,该单元格上的徽章将消失,并且ApplicationBadgeNumber将重置。我的问题是想发送关于应用程序中其他信息的通知,如会员福利。如何区分表视图中的哪一行获得徽章?假设用户收到关于会员福利的通知。我希望

当前,我的应用程序接收有关RSS源更新的通知。如果用户从通知中打开应用程序,它将打开到正确的视图控制器。如果用户未确认通知并从应用程序图标打开应用程序,则当用户打开应用程序内的菜单时,该rss源的表视图单元格中会有一个带有applicationBadgeNumber的徽章图标。选择该行后,该单元格上的徽章将消失,并且ApplicationBadgeNumber将重置。我的问题是想发送关于应用程序中其他信息的通知,如会员福利。如何区分表视图中的哪一行获得徽章?假设用户收到关于会员福利的通知。我希望标记显示在表视图的“成员福利”行中,但如果RSS提要发出通知,请标记相应的行

下面是我目前为RSS提要行添加标记的方式

在cellForRowAtIndexPath中:

if (!(indexPath.row == 0))
    {
        cell.accessoryView = nil;
    }

    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 (indexPath.section == 0)
        {
            if (indexPath.row == 0)
            {
                cell.accessoryView = actionAlertBadge;
            }
        }
    }
if (indexPath.row == 0)
        {
            ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
            WebViewController *wvc = [[WebViewController alloc]init];
            [actionAlerts setWebViewController:wvc];
            [[UAPush shared] resetBadge];
            actionAlertBadge.hidden = YES;
            [tableView reloadData];
            navController = [[KFBNavControllerViewController alloc]initWithRootViewController:actionAlerts];

            [UIView transitionWithView:appDelegate.window
                              duration:0.5
                               options:UIViewAnimationOptionTransitionFlipFromRight
                            animations:^{
                                appDelegate.window.rootViewController = navController;
                            }
                            completion:nil];
        }
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
    NSString *notificationType = appDelegate.notificationType;
    // NSLog(@"notificationType menu table: %@", notificationType);
    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 ([notificationType isEqualToString:@"action alert"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 0) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
        else if ([notificationType isEqualToString:@"member benefit"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 5) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
    }
if (actionAlertBadge.hidden == NO) {
    if ([appDelegate.notificationType isEqualToString:@"action alert"]) {
       ....
    }
    else if ([appDelegate.notificationType isEqualToString:@"member benefit"]) {
       ....
    }
在didSelectRowAtIndexPath中:

if (!(indexPath.row == 0))
    {
        cell.accessoryView = nil;
    }

    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 (indexPath.section == 0)
        {
            if (indexPath.row == 0)
            {
                cell.accessoryView = actionAlertBadge;
            }
        }
    }
if (indexPath.row == 0)
        {
            ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
            WebViewController *wvc = [[WebViewController alloc]init];
            [actionAlerts setWebViewController:wvc];
            [[UAPush shared] resetBadge];
            actionAlertBadge.hidden = YES;
            [tableView reloadData];
            navController = [[KFBNavControllerViewController alloc]initWithRootViewController:actionAlerts];

            [UIView transitionWithView:appDelegate.window
                              duration:0.5
                               options:UIViewAnimationOptionTransitionFlipFromRight
                            animations:^{
                                appDelegate.window.rootViewController = navController;
                            }
                            completion:nil];
        }
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
    NSString *notificationType = appDelegate.notificationType;
    // NSLog(@"notificationType menu table: %@", notificationType);
    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 ([notificationType isEqualToString:@"action alert"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 0) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
        else if ([notificationType isEqualToString:@"member benefit"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 5) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
    }
if (actionAlertBadge.hidden == NO) {
    if ([appDelegate.notificationType isEqualToString:@"action alert"]) {
       ....
    }
    else if ([appDelegate.notificationType isEqualToString:@"member benefit"]) {
       ....
    }
编辑:下面是我试图实现这一点的方法,但它不起作用,因为我的表视图中的notificationType字符串为NULL

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    UA_LINFO(@"Received remote notification: %@", userInfo);

    // Send the alert to UA so that it can be handled and tracked as a direct response. This call
    // is required.
    [[UAPush shared]appReceivedRemoteNotification:userInfo applicationState:application.applicationState];

    // Optionally provide a delegate that will be used to handle notifications received while the app is running
    // [UAPush shared].delegate = your custom push delegate class conforming to the UAPushNotificationDelegate protocol

    // Reset the badge after a push received (optional)
    [[UAPush shared] resetBadge];

    NSDictionary *apsInfo = [userInfo valueForKey:@"aps"];

    NSString *alertMsg = @"";

    if ([apsInfo valueForKey:@"alert"] != NULL) {
        alertMsg = [apsInfo valueForKey:@"alert"];

        if ([alertMsg containsString:@"ACTION ALERT"]) {
            notificationType = @"action alert";
        }
        else if ([alertMsg containsString:@"MEMBER BENEFIT"]) {
            notificationType = @"member benefit";
        }
    }
}
cellForRowAtIndexPath:

if (!(indexPath.row == 0))
    {
        cell.accessoryView = nil;
    }

    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 (indexPath.section == 0)
        {
            if (indexPath.row == 0)
            {
                cell.accessoryView = actionAlertBadge;
            }
        }
    }
if (indexPath.row == 0)
        {
            ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
            WebViewController *wvc = [[WebViewController alloc]init];
            [actionAlerts setWebViewController:wvc];
            [[UAPush shared] resetBadge];
            actionAlertBadge.hidden = YES;
            [tableView reloadData];
            navController = [[KFBNavControllerViewController alloc]initWithRootViewController:actionAlerts];

            [UIView transitionWithView:appDelegate.window
                              duration:0.5
                               options:UIViewAnimationOptionTransitionFlipFromRight
                            animations:^{
                                appDelegate.window.rootViewController = navController;
                            }
                            completion:nil];
        }
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
    NSString *notificationType = appDelegate.notificationType;
    // NSLog(@"notificationType menu table: %@", notificationType);
    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 ([notificationType isEqualToString:@"action alert"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 0) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
        else if ([notificationType isEqualToString:@"member benefit"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 5) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
    }
if (actionAlertBadge.hidden == NO) {
    if ([appDelegate.notificationType isEqualToString:@"action alert"]) {
       ....
    }
    else if ([appDelegate.notificationType isEqualToString:@"member benefit"]) {
       ....
    }

首先,在发送通知时,应在通知中添加类型为的字段。您将得到这样的json字典

{"aps":{"alert":{"type":"rss","text":"Hello, world!"},"sound":"default","badge":3}}
如果应用程序正在运行,则在函数中获取类型值

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary     *)dict {    
// get the type information out of the dictionary 
// now you can perform depending on this type.
 }
如果应用程序未运行,则根据

如果推送通知到达时应用程序未运行,则该方法将启动应用程序并在启动选项字典中提供相应的信息。应用程序不会调用此方法来处理推送通知。相反,您的application:willFinishLaunchingWithOptions:或application:didffinishlaunchingwithoptions:方法的实现需要获取推送通知有效负载数据并做出相应的响应


在application:didFinishLaunchingWithOptions:method中获取词典。

在AppDelegate中,首先创建一个属性:

@property (nonatomic, copy) NSString *notificationType;
然后,在你的

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
使用:

在您的CellForRowatineXpath中:

if (!(indexPath.row == 0))
    {
        cell.accessoryView = nil;
    }

    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 (indexPath.section == 0)
        {
            if (indexPath.row == 0)
            {
                cell.accessoryView = actionAlertBadge;
            }
        }
    }
if (indexPath.row == 0)
        {
            ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
            WebViewController *wvc = [[WebViewController alloc]init];
            [actionAlerts setWebViewController:wvc];
            [[UAPush shared] resetBadge];
            actionAlertBadge.hidden = YES;
            [tableView reloadData];
            navController = [[KFBNavControllerViewController alloc]initWithRootViewController:actionAlerts];

            [UIView transitionWithView:appDelegate.window
                              duration:0.5
                               options:UIViewAnimationOptionTransitionFlipFromRight
                            animations:^{
                                appDelegate.window.rootViewController = navController;
                            }
                            completion:nil];
        }
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
    NSString *notificationType = appDelegate.notificationType;
    // NSLog(@"notificationType menu table: %@", notificationType);
    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 ([notificationType isEqualToString:@"action alert"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 0) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
        else if ([notificationType isEqualToString:@"member benefit"]) {
            if (indexPath.section == 0) {
                if (indexPath.row == 5) {
                    cell.accessoryView = actionAlertBadge;
                }
            }
        }
    }
if (actionAlertBadge.hidden == NO) {
    if ([appDelegate.notificationType isEqualToString:@"action alert"]) {
       ....
    }
    else if ([appDelegate.notificationType isEqualToString:@"member benefit"]) {
       ....
    }

另一方面,我建议尽量避免进行字符串比较,并使用类似枚举的方法。

您可以根据单元格的属性进行选择,例如ifcell.title==@RSS{do this}。@FawadMasud,我知道。问题在于确定通知的内容,以便标记正确的单元格。若要更新表视图类中的变量notificationType,可以使用委托方法,也可以将其存储在所有类都可以访问的位置,例如用户默认值。我尝试使用用户默认值,但仍然无法使用。这就像我在DidReceiveMemotentification中做错了什么:但我不确定是什么。你在DidReceiveMemotentification中得到了通知类型吗?我在DidReceiveMemotentification中放了NSLog语句:但我从未看到它们。这意味着你没有得到字典。那么您是如何获得徽章号码的?您确定要在appDelegate中保存notificationType吗?因为应用程序中的代码IDReceivereMotenotification似乎并不暗示这一点。notificationtype=而不是self.notificationtype。我已将其更改为self.notificationtype,但它仍然不起作用。