Je suis en train d'ajouter/planifier une notification locale qui fournit deux actions, comme suit:Actions Non Affichage Pour UILocalNotification action
Je voudrais aussi la notification pour montrer comme une alerte bannière si je suis déjà en train d'utiliser mon téléphone, où je peux simplement glisser vers le bas pour voir les actions.
En ce moment, je planifie la notification avec succès et il apparaît sur l'écran de verrouillage. Cependant, quand je balaye à gauche, puis appuyez sur "Voir", je ne vois pas mes actions.
Voici mon code:
func addNewNotificationWith (name: String, date: Date) {
let message = "You will see this, but can't do anything! lol."
let newLocalNotif = UILocalNotification()
newLocalNotif.fireDate = dueDateWarningTime
newLocalNotif.alertBody = message
newLocalNotif.timeZone = TimeZone.autoupdatingCurrent
newLocalNotif.soundName = UILocalNotificationDefaultSoundName
newLocalNotif.category = "DueDates"
let ignoreAction = getNotificationAction(identifier: "", btnTitle: "Ignore")
let doneAction = getNotificationAction(identifier: "", btnTitle: "Done")
let category = UIMutableUserNotificationCategory()
category.identifier = "DueDates"
category.setActions([ignoreAction, doneAction], for: UIUserNotificationActionContext.minimal)
let settings = UIUserNotificationSettings(types: .alert, categories: [category])
UIApplication.shared.registerUserNotificationSettings(settings)
UIApplication.shared.scheduleLocalNotification(newLocalNotif)
print("New notification added.")
}
func getNotificationAction (identifier: String, btnTitle: String) -> UIMutableUserNotificationAction {
let incrementAction = UIMutableUserNotificationAction()
incrementAction.identifier = identifier
incrementAction.title = btnTitle
incrementAction.activationMode = UIUserNotificationActivationMode.foreground
incrementAction.isAuthenticationRequired = true
incrementAction.isDestructive = false
return incrementAction
}
Quelqu'un peut-il voir ce que je fais mal et suggérer comment y remédier?
Merci! Il me manquait category.setActions ([readAction, saveAction], pour: .default) –
Merci, il me manquait l'appel 'registerUserNotificationSettings (_ :)'. –