In iOS 10 I use new frameWork UNNotification .When setting UNNotificationTrigger I want to set a fire Date on UNNotification. But I can't find set a fire Date in UNNotificationTrigger's properties. So How can i set a fire Date in UNNotificationTrigger. I want set a fire Date in UNNotificationTrigger, how can i set
Asked
Active
Viewed 2,376 times
2
-
Add some details and efforts you have put in. Unless nobody will be able to help. – Jay Modi Dec 15 '16 at 05:13
1 Answers
3
There are two types of triggers in User Notifications framework:
UNTimeIntervalNotificationTrigger - Used for creating a notification with a set interval time:
Fire in 30 minutes (60 seconds times 30) ,
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (30*60), repeats: false)
UNCalendarNotificationTrigger- Used for creating a notification at a certain date as in your case and for repeating with specific criteria:
let date = DateComponents() date.hour = 8 date.minute = 30 let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)
The solution (Swift 3) for you would be to convert your date to a dateComponent and this can be done by:
import UserNotifications
var newComponents = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second,], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: false)

christopher.online
- 2,614
- 3
- 28
- 52

Devesh Laungani
- 129
- 3
- 12
-
There is a third type of trigger in iOS 10 `UNLocationNotificationTrigger` – christopher.online Jul 26 '17 at 11:14