Welcome to OStack Knowledge Sharing 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...