You could call cancelAllLocalNotifications
method.
- (void)switchValueChanged:(SevenSwitch *)sswitch
{
if (!sswitch.isOn) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
}
Pergunta
I'm new to Xcode and I am doing an app with UILocalNotifications from UIDatePicker. I have the following code:
- (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];
}
As you see, the notification will repeat everyday:
localNotification.repeatInterval = NSDayCalendarUnit;
I want to implement a UISwitch that when is off it will not send any notifications. Like i said, I am new to Xcode and I am a little confused on how to do it.
Thanks for the help.
Solução
You could call cancelAllLocalNotifications
method.
- (void)switchValueChanged:(SevenSwitch *)sswitch
{
if (!sswitch.isOn) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
}