UILocalNotification - repeatInterval reset (no repeat)

别来无恙 提交于 2019-12-18 09:15:16

问题


Overview

  • I am creating a notification based on an existing instance of UILocalNotification
  • Existing instance has repeatInterval set to NSWeekdayCalendarUnit

What I want to do

  • I want to set repeatInterval to no repeat,

Question

  • What is the constant that I should set repeatInterval to in order for it not to repeat ?

回答1:


Taken from Apple documentation:

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:

  1. Cancel all the notifications.
  2. Cancel only that notification.

The first option is easy, use:

cancelAllLocalNotifications

In your app delegate.

The second one requires more work. You need to go through the pending notifications (use scheduledLocalNotifications) and cancel the notification.

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.



来源:https://stackoverflow.com/questions/10359024/uilocalnotification-repeatinterval-reset-no-repeat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!