@@ -60,14 +60,14 @@ struct NotificationContentParser {
60
60
}
61
61
} else {
62
62
if #available( iOS 15 . 0 , * ) {
63
- return UNTextInputNotificationAction ( identifier: button. identifier,
64
- title: button. title,
65
- options: getOptions ( forActionButton: button) ,
66
- icon: getNotificationIcon ( forActionButton: button) )
63
+ return UNNotificationAction ( identifier: button. identifier,
64
+ title: button. title,
65
+ options: getOptions ( forActionButton: button) ,
66
+ icon: getNotificationIcon ( forActionButton: button) )
67
67
} else {
68
- return UNTextInputNotificationAction ( identifier: button. identifier,
69
- title: button. title,
70
- options: getOptions ( forActionButton: button) )
68
+ return UNNotificationAction ( identifier: button. identifier,
69
+ title: button. title,
70
+ options: getOptions ( forActionButton: button) )
71
71
}
72
72
}
73
73
}
@@ -76,15 +76,15 @@ struct NotificationContentParser {
76
76
guard let identifier = json [ JsonKey . ActionButton. identifier] as? String else { return nil }
77
77
guard let title = json [ JsonKey . ActionButton. title] as? String else { return nil }
78
78
79
+ let actionIcon = ( json [ JsonKey . ActionButton. actionIcon] as? [ AnyHashable : Any ] ) . flatMap ( ActionIcon . from ( json: ) )
79
80
return ActionButton ( identifier: identifier,
80
81
title: title,
81
82
buttonType: getButtonType ( info: json) ,
82
83
openApp: getBoolValue ( json [ JsonKey . ActionButton. openApp] ) ?? true ,
83
84
requiresUnlock: getBoolValue ( json [ JsonKey . ActionButton. requiresUnlock] ) ?? false ,
84
85
textInputTitle: json [ JsonKey . ActionButton. inputTitle] as? String ,
85
86
textInputPlaceholder: json [ JsonKey . ActionButton. inputPlaceholder] as? String ,
86
- systemImageName: json [ JsonKey . ActionButton. systemImageName] as? String ,
87
- templateImageName: json [ JsonKey . ActionButton. templateImageName] as? String )
87
+ actionIcon: actionIcon)
88
88
}
89
89
90
90
private static func getButtonType( info: [ AnyHashable : Any ] ) -> ButtonType {
@@ -120,13 +120,14 @@ struct NotificationContentParser {
120
120
121
121
@available ( iOS 15 . 0 , * )
122
122
private static func getNotificationIcon( forActionButton button: ActionButton ) -> UNNotificationActionIcon ? {
123
- if let systemImageName = button. systemImageName {
124
- return UNNotificationActionIcon ( systemImageName: systemImageName)
125
- } else if let templateImageName = button. templateImageName {
126
- return UNNotificationActionIcon ( templateImageName: templateImageName)
127
- } else {
123
+ guard let actionIcon = button. actionIcon else {
128
124
return nil
129
125
}
126
+ if actionIcon. iconType == . systemImage {
127
+ return UNNotificationActionIcon ( systemImageName: actionIcon. imageName)
128
+ } else {
129
+ return UNNotificationActionIcon ( templateImageName: actionIcon. imageName)
130
+ }
130
131
}
131
132
132
133
private enum ButtonType : String {
@@ -143,7 +144,24 @@ struct NotificationContentParser {
143
144
let requiresUnlock : Bool
144
145
let textInputTitle : String ?
145
146
let textInputPlaceholder : String ?
146
- let systemImageName : String ?
147
- let templateImageName : String ?
147
+ let actionIcon : ActionIcon ?
148
+ }
149
+
150
+ private enum ActionIconType : String , Codable {
151
+ case systemImage
152
+ case templateImage
153
+ }
154
+
155
+ private struct ActionIcon : Codable {
156
+ let iconType : ActionIconType
157
+ let imageName : String
158
+
159
+ static func from( json: [ AnyHashable : Any ] ) -> ActionIcon ? {
160
+ guard let data = try ? JSONSerialization . data ( withJSONObject: json, options: [ ] ) else {
161
+ return nil
162
+ }
163
+ return try ? JSONDecoder ( ) . decode ( ActionIcon . self, from: data)
164
+ }
148
165
}
149
166
}
167
+
0 commit comments