Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

ios - UILocalNotification - repeatInterval reset (no repeat)

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 ?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...