In meinem Projekt habe ich ein Problem: Es gibt zwei verschiedene Benachrichtigungen.Wie kann ich verschiedene UIUserNotificationSettings haben, wenn es viele Arten von Benachrichtigungen gibt
Einer von ihnen brauchen zwei UIMutableUserNotificationActions
(OK und Abbrechen) und der andere braucht nur einen (Erinnere mich später). Hier
ist der Code:
let completeAction = UIMutableUserNotificationAction()
completeAction.identifier = "OK" // the unique identifier for this action
completeAction.title = "OK" // title for the action button
completeAction.activationMode = .Background // UIUserNotificationActivationMode.Background - don't bring app to foreground
completeAction.authenticationRequired = false // don't require unlocking before performing action
completeAction.destructive = true // display action in red
let cancelAction = UIMutableUserNotificationAction()
cancelAction.identifier = "Cancel"
if #available(iOS 9.0, *) {
cancelAction.parameters = [UIUserNotificationTextInputActionButtonTitleKey : "Send"]
} else {
// Fallback on earlier versions
}
cancelAction.title = "Cancel"
if #available(iOS 9.0, *) {
cancelAction.behavior = UIUserNotificationActionBehavior.TextInput
} else {
// Fallback on earlier versions
}
cancelAction.activationMode = .Background
cancelAction.destructive = false
cancelAction.authenticationRequired = false
let todoCategory = UIMutableUserNotificationCategory() // notification categories allow us to create groups of actions that we can associate with a notification
todoCategory.identifier = "TODO_CATEGORY"
todoCategory.setActions([cancelAction, completeAction], forContext: .Minimal) // UIUserNotificationActionContext.Default (4 actions max)
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge , .Sound], categories: NSSet(array: [todoCategory]) as? Set<UIUserNotificationCategory>))
Aber es gibt nur eine Bedingung von UIUserNotificationSettings
.
Veröffentlichen Sie Ihren Code nicht als Bild. Aktualisiere deine Frage mit der tatsächlichen Code-Kopie und füge sie in die Frage ein (und richtig formatiert). – rmaddy
@rmaddy ich habe behoben. Danke. es ist mein erstes Mal, Frage zu stellen. : D – Castiel