ios - UISwitch 和 UILocalNotification 问题

标签 ios uilocalnotification uidatepicker uiswitch

我是 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 的新手,我对如何去做有点困惑。

感谢您的帮助。

最佳答案

您可以调用 cancelAllLocalNotifications 方法。

- (void)switchValueChanged:(SevenSwitch *)sswitch
{
    if (!sswitch.isOn) {
        [[UIApplication sharedApplication] cancelAllLocalNotifications];
    }
}

关于ios - UISwitch 和 UILocalNotification 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23530763/

相关文章:

ios - 什么是 UILocalNotification 重复日历用于以及如何使用

ios - UILocalNotification 我的警报每分钟触发一次 swift 2.0

ios - 使用 NSFetchRequest 按日期和单元格按时区字母顺序对部分进行排序

ios - 2 UITextField 和 1 UIDatePicker : How can I let UIDatePicker know where to display the . 日期

ios - 如何在 uidatepicker View 中将最大日期设置为今天 23 :59?

ios - 重新部署应用程序但有选择地保留设备上的旧数据

iOS 从 UIWebView 缓存内容

ios - WatchKit 通知窗框颜色

ios - subview 按钮不起​​作用

iOS UILocalNotification 是操作按钮崩溃并损坏应用程序数据