【发布时间】:2018-04-02 08:00:41
【问题描述】:
如何在每 5 天上午 10:00 重复一次 LocalNotification
我尝试了这个,但它不起作用
let content = UNMutableNotificationContent()
content.title = "Hello!"
content.body = "Hello_message_body"
content.sound = UNNotificationSound.default()
let futureTime = Date().addingTimeInterval(5 * 24 * 60 * 60)
var calendar = NSCalendar.current
calendar.timeZone = NSTimeZone.system
var components = calendar.dateComponents([.hour, .minute, .second], from: futureTime)
components.hour = 10
components.minute = 0
components.second = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
let request = UNNotificationRequest(identifier: "FiveDays", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request)
【问题讨论】:
-
而不是计算
futureTime,也许你应该使用DateComponents#day
标签: ios swift localnotification unusernotificationcenter