Skip to content

Commit

Permalink
Fix text input actionable notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Nov 17, 2017
1 parent bfb5c7b commit f4c2fc2
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions HomeAssistant/HAAPI.swift
Expand Up @@ -907,11 +907,9 @@ public class HomeAssistantAPI {
newAction.identifier = action.Identifier
newAction.isAuthenticationRequired = action.AuthenticationRequired
newAction.isDestructive = action.Destructive
var behavior: UIUserNotificationActionBehavior
if action.Behavior == "default" {
behavior = UIUserNotificationActionBehavior.default
} else {
behavior = UIUserNotificationActionBehavior.textInput
var behavior: UIUserNotificationActionBehavior = .default
if action.Behavior.lowercased() == "textinput" {
behavior = .textInput
}
newAction.behavior = behavior
let foreground = UIUserNotificationActivationMode.foreground
Expand Down Expand Up @@ -956,21 +954,19 @@ public class HomeAssistantAPI {
if action.AuthenticationRequired { actionOptions.insert(.authenticationRequired) }
if action.Destructive { actionOptions.insert(.destructive) }
if action.ActivationMode == "foreground" { actionOptions.insert(.foreground) }
if action.Behavior == "default" {
let newAction = UNNotificationAction(identifier: action.Identifier!,
title: action.Title!, options: actionOptions)
categoryActions.append(newAction)
} else if action.Behavior == "TextInput" {
var newAction = UNNotificationAction(identifier: action.Identifier!,
title: action.Title!, options: actionOptions)
if action.Behavior.lowercased() == "textinput" {
if let identifier = action.Identifier, let btnTitle = action.TextInputButtonTitle,
let place = action.TextInputPlaceholder, let title = action.Title {
let newAction = UNTextInputNotificationAction(identifier: identifier,
title: title,
options: actionOptions,
textInputButtonTitle: btnTitle,
textInputPlaceholder: place)
categoryActions.append(newAction)
newAction = UNTextInputNotificationAction(identifier: identifier,
title: title,
options: actionOptions,
textInputButtonTitle: btnTitle,
textInputPlaceholder: place)
}
}
categoryActions.append(newAction)
}
} else {
continue
Expand Down Expand Up @@ -1026,6 +1022,7 @@ public class HomeAssistantAPI {
}
if let textInput = userInput {
eventData["response_info"] = textInput
eventData["textInput"] = textInput
}
HomeAssistantAPI.sharedInstance.CreateEvent(eventType: "ios.notification_action_fired",
eventData: eventData).then { _ in
Expand Down

0 comments on commit f4c2fc2

Please sign in to comment.