我想將重複間隔設置爲用戶從日期選擇器中選擇的值。我在我的應用程序中使用了類型倒計時模式的日期選擇器。如果用戶從日期選擇器中選擇4小時15分鐘,使用下面的代碼和鬧鈴開火。在本地通知中設置repeatInterval
[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]]
但我希望通知應在每4小時15分鐘後重復,直到用戶取消爲止。我已經做了[R & d搜索了很多,但我不out.The我用至今代碼:
localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]]];
if(localNotification.fireDate){
[self _showAlert:@"Time is scheduled" withTitle:@"Daily Achiever"];
}
localNotification.timeZone = [NSTimeZone systemTimeZone];
[email protected]"alaram";
localNotification.soundName = UILocalNotificationDefaultSoundName;
[localNotification setAlertAction:@"View"];
[localNotification setRepeatInterval:[pickerTimer countDownDuration]];
//The button's text that launches the application and is shown in the alert
// [localNotification setAlertBody:[alertBodyField text]]; //Set the message in the notification from the textField's text
//[localNotification setHasAction: YES]; //Set that pushing the button will launch the application
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1
localNotification.applicationIconBadgeNumber = 1;
localNotification.repeatInterval=NSHourCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
//[alertNotification setHidden:NO]; //Set the alertNotification to be shown showing the user that the application has registered the local notification
請幫我解決。提前致謝。
嗨,恭喜你已經解決了你的問題。如果你不介意,你可以分享你的解決方案,因爲我面臨着同樣的情況,我想在每天早上和晚上的一天重複兩次本地通知,所以無法弄清楚如何做,請如果你能幫助我一些代碼 –