你好我想安排本地通知在上午9點到火平日(週一 - 週五)特定的時間和不能似乎找到如何做到這一點的任何文檔。這是我到目前爲止的代碼:斯威夫特:安排本地通知平日
@IBAction func scheduleLocal(sender: UIButton) {
guard let settings = UIApplication.sharedApplication().currentUserNotificationSettings() else { return
}
if settings.types == .None {
let ac = UIAlertController(title: "Cant Schedule", message: "No Permission", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
return
}
let notification = UILocalNotification()
notification.fireDate = NSDate()
notification.alertBody = "Come Exercise"
notification.alertAction = "Exercise Time"
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["customField1": "w00t"]
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
,並在viewDidLoad中:
let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
因爲我不知道該如何放入它,所以我覺得已經開除了。 –
您將需要安排5周的通知,即重複每週 – Paulw11
感謝您的答覆。如何添加對通知的日期和時間爲它雖然? –