这个问题已经在 SO 上得到了回答。这是参考:
但到目前为止我已经尝试过:
var fortnightPart1 = DateComponents()
fortnightPart1.weekday = Calendar.current.component(.day, from: Sdate) //(Day..here Sunday)
fortnightPart1.weekdayOrdinal = 2 //= n == (nth Day in the month...here 2nd Sunday in every month month)
fortnightPart1.hour = Calendar.current.component(.hour, from: Sdate)
fortnightPart1.minute = Calendar.current.component(.minute, from: Sdate)
fortnightPart1.second = Calendar.current.component(.second, from: Sdate)
trigger = UNCalendarNotificationTrigger(dateMatching: fortnightPart1, repeats: repeate)
Run Code Online (Sandbox Code Playgroud)
我无法在 14 天后实现它。虽然,它来自一个随机数据。任何人都可以检查代码有什么问题吗?
更新:
根据您的建议(/sf/answers/3225074821/),这是最终有效的代码!
//for 1st time notification
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = title
content.body = body …Run Code Online (Sandbox Code Playgroud) calendar uilocalnotification swift3 unnotificationrequest unnotificationtrigger