UILocalNotification - repeatInterval reset(不重复)

use*_*037 2 ios uilocalnotification

概观

  • 我正在基于现有的实例创建通知 UILocalNotification
  • 现有实例已repeatInterval设置为NSWeekdayCalendarUnit

我想做的事

  • 我想不设repeatInterval重复,

  • repeatInterval为了不重复,我应该设定的常数是多少?

Edu*_*Edu 6

取自Apple文档:

如果您指定日历单位(例如每周(NSWeekCalendarUnit)或每年(NSYearCalendarUnit)),系统将按指定的时间间隔重新安排通知以进行交付.默认值为0,表示不重复.

我假设您要以重复间隔取消通知,您可以通过两种方式执行此操作:

  1. 取消所有通知.
  2. 取消该通知.

第一个选项很简单,使用:

cancelAllLocalNotifications
Run Code Online (Sandbox Code Playgroud)

在您的应用代表中.

第二个需要更多的工作.您需要浏览待处理的通知(使用scheduledLocalNotifications)并取消通知.

为了知道要取消哪些通知,您可以userInfo在设置通知时使用该属性.例如,为每个通知设置唯一ID,因此当您取消该通知时,只需将该ID与scheduledLocalNotifications阵列中的所有ID进行比较即可.