iphone - 我如何更改 UILocalNotification 中的 UserInfo?

标签 iphone ios objective-c uilocalnotification

我有 6 个 UILocalNotifications。 每个通知都有自己的“userInfo”

  1. @“1”
  2. @“2”
  3. @“3”
  4. @"4"
  5. @“5”
  6. @"6"

然后我删除通知编号 4,并有 5 个通知:

  1. @“1”
  2. @“2”
  3. @“3”
  4. @“5”
  5. @"6"

我如何更改通知中的“userInfo”以获取:

  1. @“1”
  2. @“2”
  3. @“3”
  4. @"4"
  5. @“5”

保存代码-

// Specify custom data for the notification

NSDictionary *infoDict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%i", i] forKey:@"notif"];
localNotif.userInfo = infoDict;
 i = i + 1;

删除代码-

if (flagTable == 1)
{
    int numberPhoto = [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
    int numPhFlag = numberPhoto;
    int i = 0;
    NSLog(@"Col notif = %d", numberPhoto);
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    while (numberPhoto == numPhFlag) {
        localNotif = [[[UIApplication sharedApplication] scheduledLocalNotifications] objectAtIndex:i];
        localNotif.timeZone = [NSTimeZone localTimeZone];
        NSDateFormatter *format = [[NSDateFormatter alloc] init];
        [format setDateFormat:@"dd-MM-yyyy HH:mm"];
        NSString *itemDateWithFormat = [format stringFromDate:localNotif.fireDate];
        NSLog(@"remText2 %@ = fireDate2 %@", itemDateWithFormat, [appDel.fireDateArray objectAtIndex:row]);
        if ([itemDateWithFormat isEqualToString:[appDel.fireDateArray objectAtIndex:row]]) {
            NSLog(@"remText3 %@ = fireDate3 %@", itemDateWithFormat, [appDel.fireDateArray objectAtIndex:row]);
            [[UIApplication sharedApplication] cancelLocalNotification:localNotif];
            numPhFlag = numPhFlag - 1;
        }
        i = i + 1;
    }
    int getNot = [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
    NSLog(@"Col notif2 = %d", getNot);
}

我想遍历通知并替换其 userInfo 中的数据。

最佳答案

得到答案 =)

int notifCount = [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
for (int j = 0; j < notifCount; j++) {
    UILocalNotification *notific = [[[UIApplication sharedApplication] scheduledLocalNotifications] objectAtIndex:j];
    NSLog(@"notificBefore = %@ and j = %i", [notific.userInfo objectForKey:@"notif"], j+1);
    if ([notific.userInfo objectForKey:@"notif"] != [NSString stringWithFormat:@"%i", j+1]) {
        [[UIApplication sharedApplication] cancelLocalNotification:notific];
        NSDictionary *infoDict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%i", j+1] forKey:@"notif"];
        [notific setUserInfo:infoDict];
        NSLog(@"notificEnd = %@", [notific.userInfo objectForKey:@"notif"]);
        [[UIApplication sharedApplication] scheduleLocalNotification:notific];
    }
}

关于iphone - 我如何更改 UILocalNotification 中的 UserInfo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15924698/

相关文章:

ios - 哪种声明 IBoutlet 的方式更好

iphone - iOS 中的 Opencv 内存管理(带 ARC 的 Objective-c)

ios - UIActivityIndi​​catorView 未显示在 UIAlertView 上

ios - 如何将字符串 "$double_number"转换为 double

iphone - 在 Objective C (iPhone) 中正确声明委托(delegate)

ios - 具有多个部分的 PFQueryTableView (Swift + Parse.com)

ios - 如何正确使用 HTTP 正文进行发布?

iphone - 一次可以运行多少个 SQL 查询?

用于触摸屏设备的 JavaScript 库

iphone - IOS 5 - webview 不显示从reportviewer control(.NET) 渲染的html