未显示 UILocalNotification 操作的操作

Actions Not Showing For UILocalNotification Action

我正在尝试 add/schedule 提供两个操作的本地通知,如下所示:

如果我已经在使用 phone,我还希望通知显示为横幅提醒,我只需向下滑动即可查看操作。

现在,我已成功安排通知,它确实出现在锁定屏幕上。但是,当我向左滑动,然后点击 "View" 时,我看不到我的操作。

这是我的代码:

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
} 

任何人都可以看到我做错了什么并建议如何解决吗?

试试下面的代码 swift 3 它对我有用

    let category = UIMutableUserNotificationCategory()

    let readAction = UIMutableUserNotificationAction()
    readAction.identifier = "xx"
    readAction.isDestructive = false
    readAction.title = "Read"
    readAction.activationMode = .background
    readAction.isAuthenticationRequired = false

    let saveAction = UIMutableUserNotificationAction()
    saveAction.identifier = "zz"
    saveAction.isDestructive = false
    saveAction.title = "Save"
    saveAction.activationMode = .background
    saveAction.isAuthenticationRequired = false

    let categoryIdentifier = "category.identifier"
    category.identifier = categoryIdentifier
    category.setActions([readAction,saveAction], for: .minimal)
    category.setActions([readAction,saveAction], for: .default)

    let categories = Set(arrayLiteral: category)
    let settings = UIUserNotificationSettings(types: .alert, categories: categories)
    UIApplication.shared.registerUserNotificationSettings(settings)


    let localNotif = UILocalNotification()
    localNotif.alertBody = "testBody"
    localNotif.category = categoryIdentifier
    localNotif.fireDate = Date()?.addingTimeInterval(10)

    UIApplication.shared.scheduleLocalNotification(localNotif)