Ich brauche Ihre Hilfe für ein Projekt.
Ich habe 3 Variablen, eine für den Tag, eine andere für den Monat und die letzte für das Jahr. Wie folgt aus:Swift 3 - Lokale Benachrichtigung zu einem bestimmten Datum
var year = 2017 var month = 06 var day = 19
mag ich eine Benachrichtigung senden, auch wenn die App der Nähe ist, wenn wir zum Zeitpunkt dieses variabel sind, aber ich bin nicht wirklich gut mit Kalender und Datum. Ich habe gerade diese App für den Moment gemacht.
let myNotification = Notification.Name(rawValue:"MyNotification")
override func viewDidLoad() {
super.viewDidLoad()
let nc = NotificationCenter.default
nc.addObserver(forName:myNotification, object:nil, queue:nil, using:catchNotification)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let nc = NotificationCenter.default
nc.post(name:myNotification,
object: nil,
userInfo:["message":"Hello there!", "date":Date()])
}
func catchNotification(notification:Notification) -> Void {
print("Catch notification")
guard let userInfo = notification.userInfo,
let message = userInfo["message"] as? String,
let date = userInfo["date"] as? Date else {
print("No userInfo found in notification")
return
}
let alert = UIAlertController(title: "Notification!",
message:"\(message) received at \(date)",
preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
Vielen Dank im Voraus
Was ist der Wert von "yourFireDate"? – Rombond
ist ein 'Date'-Objekt, das Sie mit Ihren Variablen Jahr, Monat und Tag initialisieren. –
Also setze ich 'let yourFireDate = Jahr + Monat + Tag' – Rombond