我使用UIDatePicker
和NSLocalNotification
制作了余数申请表。剩下的应用程序已准备好并且正在运行,但其余时间会在几秒钟后触发。
以下是代码:
-(void)addRemainder
{
NSDateFormatter *dateform=[[NSDateFormatter alloc]init];
dateform.dateFormat = @"dd-MM-yyyy HH:mm";
NSString *formattedDate = [dateform stringFromDate:datePicker.date];
date=[dateform dateFromString:formattedDate];
str=[dateform stringFromDate:date];
if(textField1.text!=nil)
{
notification = [[UILocalNotification alloc] init];
notification.fireDate = date;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = textField1.text;
notification.alertAction=@"Show me the item";
notification.soundName = UILocalNotificationDefaultSoundName;
NSUInteger nextBadgeNumber = [[[UIApplication sharedApplication] scheduledLocalNotifications] count] + 1;
notification.applicationIconBadgeNumber = nextBadgeNumber;
notification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
if ([remainderr isEqualToString:@"edit"])
{
[remainder replaceObjectAtIndex:([index integerValue]) withObject:textField1.text];
[TimeDate replaceObjectAtIndex:([index integerValue]) withObject: str];
[self.navigationController popViewControllerAnimated:YES];
}
答案 0 :(得分:0)
我猜你的问题将出现在NSDateFormatter上,因为你已经添加了秒数,它也会返回秒数。因此会有几秒钟的延迟。
将您的NSDateFormatter更改为
@"dd-MM-YYYY HH:mm"
说明:
LocalNotification将设置为@“dd-MM-YYYY HH:mm:SS”格式,因此我们必须将其转换为格式@“dd-MM-YYYY HH:mm”(无秒)。