@@ -134,6 +134,60 @@ func handleNotification(forResponse response: UNNotificationResponse) {
134134 exit ( 0 )
135135}
136136
137+ // Adds messageButton (always needed) and messageButtonAction (when defined)
138+ func processMessageButton( notificationCenter: UNUserNotificationCenter , messageContent: MessageContent ,
139+ rootElements: RootElements ) ->
140+ ( [ AnyHashable : Any ] , UNNotificationCategory ) {
141+ // Var declaration
142+ var tempCategory = UNNotificationCategory ( identifier: " banner " , actions: [ ] , intentIdentifiers: [ ] ,
143+ options: . customDismissAction)
144+ var messageButtonAction = [ AnyHashable: Any] ( )
145+ // If we have a value for messageButton passed
146+ if messageContent. messageButton != nil {
147+ // Create an action object
148+ let notificationAction = UNNotificationAction ( identifier: " messagebutton " ,
149+ title: messageContent. messageButton ?? " " ,
150+ options: [ ] )
151+ // Amend tempCategory
152+ tempCategory = UNNotificationCategory ( identifier: " banner " , actions: [ notificationAction] ,
153+ intentIdentifiers: [ ] ,
154+ options: . customDismissAction)
155+ // If verbose mode is enabled
156+ if rootElements. verboseMode != nil {
157+ // Progress log
158+ NSLog ( " \( #function. components ( separatedBy: " ( " ) [ 0 ] ) - messagebutton processed " )
159+ }
160+ // If we have a values for messageButton and messageButtonAction passed
161+ if messageContent. messageButtonAction != nil {
162+ // Add taskPath from messagAction to messageButtonAction
163+ messageButtonAction [ " taskPath " ] = messageContent. messageButtonAction ? [ 0 ] . taskPath
164+ // Add taskArguments from messageButtonAction
165+ messageButtonAction [ " taskArguments " ] =
166+ messageContent. messageButtonAction ? [ 0 ] . taskArguments
167+ // If verbose mode is enabled
168+ if rootElements. verboseMode != nil {
169+ // Progress log
170+ NSLog ( """
171+ \( #function. components ( separatedBy: " ( " ) [ 0 ] ) - messageButtonAction - taskPath: \
172+ \( messageButtonAction [ " taskPath " ] ?? " " ) ,
173+ taskArguments: \( messageButtonAction [ " taskArguments " ] ?? [ ] )
174+ """ )
175+ }
176+ // Return tempCategory and tempUserInfo
177+ return ( messageButtonAction, tempCategory)
178+ }
179+ // If we don't have a value for messageButton
180+ } else {
181+ // If verbose mode is enabled
182+ if rootElements. verboseMode != nil {
183+ // Progress log
184+ NSLog ( " \( #function. components ( separatedBy: " ( " ) [ 0 ] ) - no messagebutton defined " )
185+ }
186+ }
187+ // Return empty userInfo for messageButtonAction and tempCategory
188+ return ( [ : ] , tempCategory)
189+ }
190+
137191// Post the notification
138192func postNotification( notificationCenter: UNUserNotificationCenter , notificationContent: UNMutableNotificationContent ,
139193 messageContent: MessageContent , passedBase64: String , rootElements: RootElements ) {
@@ -207,11 +261,11 @@ func processNotificationActions(userInfoKey: String, userInfo: [AnyHashable: Any
207261 } else {
208262 // Post error
209263 postToNSLogAndStdOut ( logLevel: " ERROR " , logMessage:
210- """
211- Running: \( messageActionDict [ " taskPath " ] ?? " " )
212- \( messageActionDict [ " taskArguments " ] ?? [ ] ) failed with \( taskOutput) .
213- """ , functionName: #function. components ( separatedBy: " ( " ) [ 0 ] ,
214- verboseMode: " enabled " )
264+ """
265+ Running: \( messageActionDict [ " taskPath " ] ?? " " )
266+ \( messageActionDict [ " taskArguments " ] ?? [ ] ) failed with \( taskOutput) .
267+ """ , functionName: #function. components ( separatedBy: " ( " ) [ 0 ] ,
268+ verboseMode: " enabled " )
215269 }
216270 }
217271 }
0 commit comments