【发布时间】:2014-05-08 00:33:10
【问题描述】:
我是 Xcode 的新手,我正在使用来自 UIDatePicker 的 UILocalNotifications 做一个应用程序。我有以下代码:
- (IBAction)save {
// Get the current date
NSDate *pickerDate = [self.datePicker date];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = @"Reminder";
localNotification.soundName = @"Alert1.wav";
localNotification.alertAction = @"view";
localNotification.repeatInterval = NSDayCalendarUnit;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
// Dismiss the view controller
[self dismissViewControllerAnimated:YES completion:nil];
}
如您所见,通知每天都会重复:
localNotification.repeatInterval = NSDayCalendarUnit;
我想实现一个 UISwitch,当它关闭时它不会发送任何通知。就像我说的,我是 Xcode 的新手,我对如何做有点困惑。
感谢您的帮助。
【问题讨论】:
标签: ios uilocalnotification uidatepicker uiswitch