我想知道如何在每个月的第一天快速重复发送本地通知。因此,在1月1日提醒您。 2月1日,同样的提醒,依此类推。最好使用日期组件。
答案 0 :(得分:0)
let center = UNUserNotificationCenter.current()
//create the content for the notification
let content = UNMutableNotificationContent()
content.title = " Title"
content.subtitle = "SubTitle"
content.body = "jvsvsvasvbasbvfasfv"
content.sound = UNNotificationSound.default
var dateComp = DateComponents()
dateComp.month = 1;
dateComp.day = 1;
dateComp.hour = 00;
dateComp.minute = 00;
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComp, repeats: true)
//create request to display
let request = UNNotificationRequest(identifier: "ContentIdentifier", content: content, trigger: trigger)
//add request to notification center
center.add(request) { (error) in
if error != nil {
print("error \(String(describing: error))")
}
}
用户可以参考此link更多信息。