2013-03-07 64 views
-2

我是新手來UILocalNotification.Im創建一個藥物提醒應用程序。我想在UILocalNotification中顯示藥物攝入的時機。是否有可能每天提醒我三次單一標題?是否可以爲一個本地通知添加多個提醒?

對於例如:我要帶一個平板電腦每天3 times.How設置三個提醒一個標題(提示)。而我也想設定開始日期和結束日期爲reminder.Kindly請給一個想法感謝。提前。

+0

你是否檢查了這一點? http://stackoverflow.com/questions/6966365/uilocalnotification-repeat-interval-for-custom-alarm-sun-mon-tue-wed-thu-f – nhisyam 2013-03-07 03:48:17

+0

Thanks.I將檢查.. @ nhisyam – 2013-03-07 03:50:52

+0

你肯定可能 – Ravindhiran 2013-03-07 03:58:12

回答

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]; 
+0

Thanks..1更多問題。可以爲UILocalNotification添加開始日期和結束日期嗎?像在默認iPhone日曆添加事件? @Ravindhiran – 2013-03-07 04:21:33

+0

我沒有'嘗試添加開始日期和結束日期爲UILocalNotification .. – Ravindhiran 2013-03-07 04:29:39

+0

沒有。 LocalNotification中沒有startDate和endDate。 – Yashesh 2013-03-07 05:23:42

相關問題