[英]Local Notification issue
i am using following code for local notification 我正在使用以下代码进行本地通知
for (int i=0;i<newBirthDates.count;i++)
{
NSDate *date =[Formatter1 dateFromString:[newBirthDates objectAtIndex:i ]];
NSComparisonResult result = [date compare:todaydate];
if(result == NSOrderedSame)
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = date;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"birthdate notification";
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
}
newBirthdate is array with dates in it
Formatter1 =MM/dd.
lets say one of the date in newbrithdate is 18/3 so what i do is i change my computer 可以说newbrithdate中的日期之一是18/3,所以我要做的就是更换计算机
date to 17/3 and 11.59 pm then i wait for 1 minute and it turn 18/3 but i dont get any any notification time in my simulator always same to my computer time. 日期到17/3和11.59 pm,然后我等待1分钟,它变成18/3,但我在模拟器中没有得到任何通知时间,该时间始终与计算机时间相同。
You are storing formatted date string in array(in MM/dd format) and converting it back to date for setting notification. 您将格式化的日期字符串存储在数组中(以MM / dd格式),并将其转换回日期以设置通知。
Lets do you a simple check!! 让您做一个简单的检查!
NSDateFormatter *Formatter1 = [[NSDateFormatter alloc]init];
Formatter1.dateFormat =@"MM/dd";
NSDate *today = [NSDate date];// take current date
NSString *initialDateString =[Formatter1 stringFromDate:today]; // formatted date string(in MM/dd)
NSDate *dateFromFormatter = [Formatter1 dateFromString:initialDateString]; // Date from the formatted string(In your case taking from array)
NSString *finalDateString = [Formatter1 stringFromDate:dateFromFormatter];// formatted string from new date
// lets take a look wether both are same
NSLog(@"Initial date string: %@",initialDateString);
NSLog(@"Final date string : %@",finalDateString);
// Both date strings are same
NSLog(@"Actual date : %@",today);
NSLog(@"Formatted date : %@",dateFromFormatter);
//But see both dates are entirely different
output 输出
Initial date string: 03/18 初始日期字符串:03/18
Final date string : 03/18 最终日期字符串:03/18
Actual date : 2013-03-18 12:15:45 +0000 实际日期:2013-03-18 12:15:45 +0000
Formatted date : 2000-03-17 18:30:00 +0000 格式化日期:2000-03-17 18:30:00 +0000
Then how will you get notification?? 那么您将如何获得通知?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.