Reputation: 1765
I'm implementing local notification in my app. In a screen, i placed two textfield, with time. For example,the first textfield having 2.44 pm and 2nd textfield having 2.45pm . The first textfield 's time local notification is not firing on 2.44 pm. but 2.45pm notification is firing correctly. And, 2.44pm notification displaying with 2.45 pm.
// viewcontroller.m file
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
{
if ([MorningTimelbl.text length]>0)
{
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"It's time to take your eye drops";
notif.alertAction = @"Morning Notification";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.repeatInterval = NSDayCalendarUnit;
NSDictionary *mornDict = [NSDictionary dictionaryWithObject:MorningTimelbl.text
forKey:kRemindMeNotificationDataKey];
notif.userInfo = mornDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
if ([LunchTimelbl.text length]>0)
{
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"It's time to take your eye drops";
notif.alertAction = @"Lunch Notification";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.repeatInterval = NSDayCalendarUnit;
NSDictionary *lunchDict = [NSDictionary dictionaryWithObject:LunchTimelbl.text
forKey:kRemindMeNotificationDataKey];
notif.userInfo = lunchDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
}
//appdelegate.m
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
message:notification.alertBody
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}
where i did mistake? Thanks in advance.
Upvotes: 1
Views: 544
Reputation: 3089
Change as per you want:
FOR MorningTimelbl.text
notif.fireDate = Morningtime-date;
// set date as you want at Morningtime-dateFOR next(second-Notification) LunchTimelbl.text
notif.fireDate = LunchTime-date;
// set date as you want at LunchTime-dateUpvotes: 1