gpt4 book ai didi

ios - UISwitch 和 UILocalNotification 问题

转载 作者:行者123 更新时间:2023-11-29 02:58:50 26 4
gpt4 key购买 nike

我是 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com