是否可以为一个本地通知添加多个提醒?

时间:2013-03-07 03:43:58

标签: iphone ios objective-c uilocalnotification ekevent

我是新手到UILocalNotification.Im创建一个药物提醒应用程序。我想在UILocalNotification中显示药物摄入时间。是否有可能每天三次提醒我单个标题?

例如:我每天服用一片平板电脑3次。如何为一个标题设置三个提醒。(提醒)。此外,我还想设置startdate和Enddate作为提醒.Kindly Pls给出一个想法谢谢提前。

1 个答案:

答案 0 :(得分:1)

试试这个

- (IBAction) scheduleReminder:(id) sender {
[txtEvent resignFirstResponder];
if ([txtEvent.text isEqualToString:@""]) {
    CustomAlertView* alertView = [[CustomAlertView alloc] initWithTitle:@""
                                                        message:@"Please enter your reminder title" delegate:self
                                              cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];

    return;
}
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

// Get the current date
NSDate *pickerDate = [datePicker date];

// Break the date up into components
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit )
                                               fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
                                               fromDate:pickerDate];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
[df setTimeStyle:NSDateFormatterShortStyle];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];

NSDate *itemDate = [calendar dateFromComponents:dateComps];

localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
NSString *strAlertBody=txtEvent.text;
localNotif.fireDate =itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = strAlertBody;
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:txtEvent.text
                                                     forKey:@"kRemindMeNotificationDataKey"];
localNotif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];    
}





   //// ---------- list of notification in arrarrayNotification-------
 NSArray   *arrayNotification = [[UIApplication sharedApplication] scheduledLocalNotifications];

  UILocalNotification *notif = [arrayNotification objectAtIndex:indexPath.row];