0

我正在为表中的某些行设置特定日期和时间的本地通知。所以考虑

案例1:当用户第一次设置本地通知时,他从日期选择器中选择日期,我将它传递给本地通知对象firedate。

NSArray *notificationarray = [[UIApplication sharedApplication]scheduledLocalNotifications];
        if([notificationarray count]== 0)
        {
            m_alarmLocalNotification = [[UILocalNotification alloc] init];
            m_alarmLocalNotification.fireDate = DateTime;
            m_alarmLocalNotification.timeZone = [NSTimeZone defaultTimeZone];

            NSDictionary *infoDict = [NSDictionary dictionaryWithObject:m_Name forKey:@"ID"];
            m_alarmLocalNotification.userInfo = infoDict;

            [[UIApplication sharedApplication] scheduleLocalNotification:m_alarmLocalNotification];         

case2:修改本地通知日期。

    NSArray *notificationarray  = [[UIApplication sharedApplication]scheduledLocalNotifications];
                for (int i = 0;i < [notificationarray count];i++)
                {
                    UILocalNotification *notificationObject=[notificationarray objectAtIndex:i];
                    NSString *Name=[notificationObject.userInfo valueForKey:@"ID"];

                    if(Name isEqualToString:m_Name])
                    {
                        [[UIApplication sharedApplication] cancelLocalNotification:notificationObject];
                    m_alarmLocalNotification = [[UILocalNotification alloc] init];
                    m_alarmLocalNotification.fireDate = DateTime;
                    m_alarmLocalNotification.timeZone = [NSTimeZone defaultTimeZone];      


                    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:m_noteName forKey:@"ID"];
                    m_alarmLocalNotification.userInfo = infoDict;

                    [[UIApplication sharedApplication] scheduleLocalNotification:m_alarmLocalNotification];   
                    }
                   else
                   {

                    m_alarmLocalNotification = [[UILocalNotification alloc] init];
                    m_alarmLocalNotification.fireDate = DateTime;
                    m_alarmLocalNotification.timeZone = [NSTimeZone defaultTimeZone];      


                    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:m_noteName forKey:@"ID"];
                    m_alarmLocalNotification.userInfo = infoDict;

                    [[UIApplication sharedApplication] scheduleLocalNotification:m_alarmLocalNotification]; 
                }         

        }           

案例3:删除本地通知。

NSArray *notificationarray =  [[UIApplication sharedApplication]scheduledLocalNotifications];
        NSLog(@"notification count:%d",[notificationarray count]);
        for (int i = 0;i < [notificationarray count];i++)
        {
            UILocalNotification *notificationObject=[notificationarray objectAtIndex:i];
            NSString *Name=[notificationObject.userInfo valueForKey:@"ID"];
            if([Name isEqualToString:m_Name])
            {
                [[UIApplication sharedApplication] cancelLocalNotification:notificationObject];
            }
        }

面临的问题。0) 我不确定我的做法是否正确。1)即使我删除我的应用程序并重新安装它,默认的预定通知数组也不会被释放。我的意思是它包含一些以前的通知。2)每当我删除我的单元格时,我希望本地通知应该被删除。

问候兰吉特

4

1 回答 1

0

如果您在修改通知时使用以下代码,情况如何

NSArray *notificationarray  = [[UIApplication sharedApplication] scheduledLocalNotifications];
    [notificationarray enumerateObjectsUsingBlock:^(UILocalNotification *notification,NSUInteger idx, BOOL *stop) {
        if ([[notification.userInfo valueForKey:@"ID"] isEqual:@""]) {
            notification.fireDate = [NSDate date];
        }
    }];
于 2012-12-28T07:33:06.310 回答