Add Local Notification in iOS 10 - Swift 3
So habe ich versucht, dem neuen UNUserNotificationCenter eine Benachrichtigung hinzuzufügen, aber anscheinend verstehe ich das nicht.
Mein View Controller hat eine Aktion:
@IBAction func sendPressed(_ sender: AnyObject) {
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "What up?"
content.sound = UNNotificationSound.default()
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error) in
print(error)
}
print("should have been added")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let center = UNUserNotificationCenter.current()
center.requestAuthorization([.alert, .sound]) { (granted, error) in
}
}
Und ich habe einNotification Content Extension
im Projekt auch, aber es scheint überhaupt nicht ausgelöst zu werden, irgendwelche Ideen, was mir fehlt? Ich versuche das Beispiel aus der Benutzerdokumentation, aber es sagt mir nicht viel mehr oder ich habe es verpasst.
Hier:https: //developer.apple.com/reference/usernotifications/unmutablenotificationconten
Ebenfalls:https: //developer.apple.com/reference/usernotificationsu https: //developer.apple.com/reference/usernotification
Bearbeiten
So hat es geschafft, die App in den Hintergrund zu stellen.