UILocalNotification-repeatInterval重设(无重复) [英] UILocalNotification - repeatInterval reset (no repeat)
问题描述
概述
- 我正在基于
UILocalNotification
的现有实例创建通知
- 现有实例的
repeatInterval
设置为NSWeekdayCalendarUnit
- I am creating a notification based on an existing instance of
UILocalNotification
- Existing instance has
repeatInterval
set toNSWeekdayCalendarUnit
我想做什么
- 我想将
repeatInterval
设置为不重复
- I want to set
repeatInterval
to no repeat,
问题
- 为使其不重复,我应该将
repeatInterval
设置为什么常数?
- What is the constant that I should set
repeatInterval
to in order for it not to repeat ?
推荐答案
摘自Apple文档:
如果您分配日历单位,例如每周(NSWeekCalendarUnit)或 每年(NSYearCalendarUnit),系统会重新安排通知的时间 以指定的时间间隔交付. 默认值为0,即 表示不要重复.
If you assign an calendar unit such as weekly (NSWeekCalendarUnit) or yearly (NSYearCalendarUnit), the system reschedules the notification for delivery at the specified interval. The default value is 0, which means don't repeat.
我假设您想以重复间隔取消通知,您可以通过两种方式做到这一点:
I assume you want to cancel the notification with the repeating interval, you can do that in two ways:
- 取消所有通知.
- 取消仅该通知.
- Cancel all the notifications.
- Cancel only that notification.
第一个选项很简单,使用:
The first option is easy, use:
cancelAllLocalNotifications
在您的应用程序委托中.
In your app delegate.
第二个需要更多的工作.您需要浏览待处理的通知(使用scheduledLocalNotifications
)并取消该通知.
The second one requires more work. You need to go through the pending notifications (use scheduledLocalNotifications
) and cancel the notification.
为了知道要取消的通知,可以在设置通知时使用userInfo
属性.例如,为每个通知设置唯一的ID,这样,当您取消该通知时,只需将该ID与scheduledLocalNotifications
数组中的所有ID进行比较即可.
In order to know which notifications is going to be canceled you can use the userInfo
property when you set the notification. For example set an unique ID for every notification so when you cancel that notification you simply compare that ID with all the IDs in your scheduledLocalNotifications
array.
这篇关于UILocalNotification-repeatInterval重设(无重复)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!