-(void)schedulenotificationfortimeinterval:(NSString *)id1
{
NSLog(@"selected value %d",selectedvalue);
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"MMM dd,yyyy hh:mm a"];
UILocalNotification *localNotification2 = [[UILocalNotification alloc] init];
// localNotification2. fireDate = [[formatter dateFromString:[NSString stringWithFormat:@"%@ %@",[MedicationDict valueForKey:@"Starting"],[MedicationDict valueForKey:@"Ending"]]] dateByAddingTimeInterval:0];
if(selectedvalue==0)
{
NSLog(@"dk 0000");
localNotification2.fireDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ %@",[MedicationDict valueForKey:@"Starting"],[MedicationDict valueForKey:@"Ending"]]] ;//now
localNotification2.applicationIconBadgeNumber = 1;
localNotification2.repeatInterval=NSDayCalendarUnit;
}
if(selectedvalue==1)
{
NSLog(@"dk 1111");
for( int u = 0; u <= 2 ;u++)
{
localNotification2.fireDate = [[formatter dateFromString:[NSString stringWithFormat:@"%@ %@",[MedicationDict valueForKey:@"Starting"],[MedicationDict valueForKey:@"Ending"]]] dateByAddingTimeInterval:43200.0*u] ;// 12 hr
localNotification2.repeatInterval=NSDayCalendarUnit;
localNotification2.alertBody = [NSString stringWithFormat:@"Friendly reminder to take %@ %@ at %@.",[MedicationDict objectForKey:@"DrugName"],[MedicationDict objectForKey:@"Frequency"],[MedicationDict objectForKey:@"Ending"]];
localNotification2.alertAction = @"Notification";
localNotification2.soundName=UILocalNotificationDefaultSoundName;
localNotification2.applicationIconBadgeNumber = 2;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];
NSLog(@"all notifications %@",[[UIApplication sharedApplication]scheduledLocalNotifications]);
}
// localNotification2.repeatInterval=NSDayCalendarUnit;
}
if(selectedvalue==2)
{
NSLog(@"dk 22222");
for( int u = 0; u <= 3 ;u++)
{
localNotification2.fireDate = [[formatter dateFromString:[NSString stringWithFormat:@"%@ %@",[MedicationDict valueForKey:@"Starting"],[MedicationDict valueForKey:@"Ending"]]] dateByAddingTimeInterval:28800.0*u] ;//8 hr
localNotification2.repeatInterval=NSDayCalendarUnit;
localNotification2.alertBody = [NSString stringWithFormat:@"Friendly reminder to take %@ %@ at %@.",[MedicationDict objectForKey:@"DrugName"],[MedicationDict objectForKey:@"Frequency"],[MedicationDict objectForKey:@"Ending"]];
localNotification2.alertAction = @"Notification";
localNotification2.soundName=UILocalNotificationDefaultSoundName;
localNotification2.applicationIconBadgeNumber = 3;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];
NSLog(@"all notifications %@",[[UIApplication sharedApplication]scheduledLocalNotifications]);
}
// localNotification2.repeatInterval=NSDayCalendarUnit;
}
if(selectedvalue==3)
{
NSLog(@"dk 3333");
for( int u = 0; u <= 4 ;u++)
{
localNotification2.fireDate = [[formatter dateFromString:[NSString stringWithFormat:@"%@ %@",[MedicationDict valueForKey:@"Starting"],[MedicationDict valueForKey:@"Ending"]]] dateByAddingTimeInterval:21600.0*u] ;//6 hr
localNotification2.repeatInterval=NSDayCalendarUnit;
localNotification2.alertBody = [NSString stringWithFormat:@"Friendly reminder to take %@ %@ at %@.",[MedicationDict objectForKey:@"DrugName"],[MedicationDict objectForKey:@"Frequency"],[MedicationDict objectForKey:@"Ending"]];
localNotification2.alertAction = @"Notification";
localNotification2.soundName=UILocalNotificationDefaultSoundName;
localNotification2.applicationIconBadgeNumber = 4;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];
NSLog(@"all notifications %@",[[UIApplication sharedApplication]scheduledLocalNotifications]);
}
// localNotification2.repeatInterval=NSDayCalendarUnit;
}
// localNotification2.repeatInterval=NSDayCalendarUnit;
NSLog(@"date is %@ %@",[MedicationDict valueForKey:@"Starting"],[MedicationDict valueForKey:@"Ending"]);
localNotification2.timeZone = [NSTimeZone localTimeZone];
localNotification2.alertBody = [NSString stringWithFormat:@"Friendly reminder to take %@ %@ at %@.",[MedicationDict objectForKey:@"DrugName"],[MedicationDict objectForKey:@"Frequency"],[MedicationDict objectForKey:@"Ending"]];
localNotification2.alertAction = @"Notification";
localNotification2.soundName=UILocalNotificationDefaultSoundName;
//localNotification2.applicationIconBadgeNumber = 1;
// infoDict = [NSDictionary dictionaryWithObject:id1 forKey:@"did"];
// localNotification2.userInfo = infoDict;
// [[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];
// NSLog(@"all notifications %@",[[UIApplication sharedApplication]scheduledLocalNotifications]);
// [[UIApplication sharedApplication] cancelAllLocalNotifications];//dk
}