В настоящее время мое приложение получает уведомления об обновлениях в RSS-канал. Если пользователь открывает приложение из уведомления, он открывается на правильный контроллер представления. Если пользователь не подтверждает уведомление и открывает приложение из значка приложения, когда пользователь открывает меню в приложении, ячейка представления таблицы для этого rss-канала имеет значок значка с именем applicationIconBadgeNumber. После выбора этой строки значок на этой ячейке уходит, а номер приложения IconBadgeNumber сбрасывается. Мой вопрос заключается в желании отправлять уведомления о другой информации в приложении, например, о преимуществах членов. Как я могу отличить, какая строка в представлении таблицы получает значок? Скажите, что пользователь получает уведомление о пользе участника. Я хотел бы, чтобы значок появлялся в строке преимуществ членов табличного представления, но если есть уведомление из RSS-канала, значка соответствующей строки.Значок уведомлений в ячейке UITableView
Вот как я сейчас добавляю значок для строки 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;
}
}
}
в didSelectRowAtIndexPath:
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];
}
EDIT: Вот как я пытаюсь сделать это, но он не работает, потому что моя NotificationType строка с моей точки зрения этой таблицы НОЛЬ.
- (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:
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 (cell.title == @ "RSS") {сделать это}. –
@FawadMasud, я это знаю. Проблема заключается в определении содержимого уведомления, поэтому правильная ячейка помечена значком. – raginggoat