用按钮打开和关闭报警通知
问题描述:
我正在创建一个具有单个闹钟的时钟应用程序。用按钮打开和关闭报警通知
我有一个按钮来设置闹钟,一个打开闹钟的按钮和一个关闭闹钟的按钮。使用本地通知
SET按钮的工作原理:
UILocalNotification *scheduledAlert;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
scheduledAlert = [[UILocalNotification alloc] init];
scheduledAlert.applicationIconBadgeNumber=1;
scheduledAlert.fireDate = alarmPicker.date;
scheduledAlert.timeZone = [NSTimeZone defaultTimeZone];
scheduledAlert.repeatInterval = NSDayCalendarUnit;
[email protected]"alarm_clock_ringing.wav";
scheduledAlert.alertBody = @"I’d like to get your attention again!";
[[UIApplication sharedApplication]
scheduleLocalNotification:scheduledAlert];
一切工作就好了。
但是,我不知道如何编写On和Off按钮。
答
对于关闭按钮,你必须使用类似CancelAllCurrentNotifications
。
我真的会建议不要CancelAllCurrentNotifications,请看看这篇文章:http://weblog.bignerdranch.com/780-notifications-part-3-gotchas/ – Daniel 2012-08-13 00:11:07