日期为错误日志的通知

时间:2014-03-20 11:34:26

标签: ios nsdate uilocalnotification nscalendar nsdatecomponents

//get time from local storage 


NSUserDefaults *timeExam = [NSUserDefaults standardUserDefaults];
            NSString *timeSelected =[timeExam objectForKey:@"timeExam4"];

                NSDateFormatter *timeformater = [[NSDateFormatter alloc] init];
                [timeformater setLocale:[NSLocale currentLocale]];
                NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
                [timeformater setTimeZone:timeZone];
                [timeformater setDateFormat:@"EEEE-dd-MMMM-yyyy HH:mm a"];


                NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
                //convert the time string to date
                NSDate *ExamTime = [timeformater dateFromString:timeSelected];
                NSLog(@"examTime=%@",ExamTime);
                NSDateComponents *comps = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:ExamTime];
                [comps setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

    //and this is the notification for ExamTime:

    UILocalNotification *notification = [[UILocalNotification alloc] init];
                        notification.alertBody = @"local notification on exam day";
                        [notification setFireDate:ExamTime];
                        [notification setSoundName:UILocalNotificationDefaultSoundName];
                        notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
                        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

当日志更改时间并且通知未运行时请帮助我,谢谢

0 个答案:

没有答案