-4
發送通知我想通知在每月的第一天發送給用戶。我怎樣才能做到這一點?這是一個通知,只有本地不是遠程的。如何在某一特定日期在斯威夫特3
發送通知我想通知在每月的第一天發送給用戶。我怎樣才能做到這一點?這是一個通知,只有本地不是遠程的。如何在某一特定日期在斯威夫特3
你應該有這個通知代碼在一個特定的日期。
let alarmTime = Date().addingTimeInterval(60 * 60 * 24 * 7 - 300) /// you should make changes here according to your requirement.
let components = Calendar.current.dateComponents([.weekday, .hour, .minute], from: alarmTime)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
let content = UNMutableNotificationContent()
content.title = "Notification Demo"
content.subtitle = "Demo"
content.body = "Notification on specific date!!"
let request = UNNotificationRequest(
identifier: "identifier",
content: content,
trigger: trigger
)
首先,你必須註冊通知疾如
func registerLocal(sender: AnyObject) {
let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
}
然後安排爲
func scheduleLocal(sender: AnyObject) {
let notification = UILocalNotification()
notification.fireDate = // give the next first date
notification.alertBody = "this is your notification"
notification.alertAction = "be awesome!"
notification.soundName = UILocalNotificationDefaultSoundName
notification.repeatInterval = NSCalendarUnit.NSCalendarUnitMonth
notification.userInfo = ["CustomField1": "w00t"]
UIApplication.sharedApplication().scheduleLocalNotification(notification)
首先讓我們瞭解您嘗試和沒有工作 – Alistra
見請不降低我的問題的投票。我一直在花費最少的時間發送通知。我所得到的只是代碼,但是我把這個代碼放在哪裏。請我是新手幫助我,而不是僅僅降低的問題選票,使之成爲我不可能問堆棧溢出的問題。我厭倦了這個! –