如何在每月的第一天重复本地通知-swift
我想知道如何在每个月的第一天以swift的形式发出本地通知。所以在1月1日,提醒一下。在2月1日,同样的提醒,等等。最好使用日期组件如何在每月的第一天重复本地通知-swift,swift,xcode,usernotifications,Swift,Xcode,Usernotifications,我想知道如何在每个月的第一天以swift的形式发出本地通知。所以在1月1日,提醒一下。在2月1日,同样的提醒,等等。最好使用日期组件 首先,我们需要获得默认的“UNUserNotificationCenter” 创建“未通知内容” 创建“UNCalendarNotificationTrigger” 创建“UNNotificationRequest” 将“UNNotificationRequest”添加到“UNUserNotificationCenter” 用户可以参考此详细信息。@Evac re
用户可以参考此详细信息。@Evac repeats标志在UNCalendarNotificationTrigger right?中设置为true?。所以我想应该重复一遍。您可以通过在iPhone中手动更改日期来测试这一点。
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))")
}
}