@@ -38,10 +38,17 @@ func makeNotificationContent(_ notification: Notification) throws -> UNNotificat
38
38
arguments: nil )
39
39
}
40
40
41
- content. userInfo = [
42
- " __EXTRA__ " : notification. extra as Any ,
43
- " __SCHEDULE__ " : notification. schedule as Any ,
44
- ]
41
+ var userInfo : [ String : Any ] = [ : ]
42
+
43
+ if let extra = notification. extra {
44
+ userInfo [ " __EXTRA__ " ] = extra
45
+ }
46
+
47
+ if let schedule = notification. schedule {
48
+ userInfo [ " __SCHEDULE__ " ] = scheduleToDictionary ( schedule)
49
+ }
50
+
51
+ content. userInfo = userInfo
45
52
46
53
if let actionTypeId = notification. actionTypeId {
47
54
content. categoryIdentifier = actionTypeId
@@ -66,6 +73,56 @@ func makeNotificationContent(_ notification: Notification) throws -> UNNotificat
66
73
return content
67
74
}
68
75
76
+ func scheduleToDictionary( _ schedule: NotificationSchedule ) -> [ String : Any ] {
77
+ switch schedule {
78
+ case . at( let date, let repeating) :
79
+ return [
80
+ " type " : " at " ,
81
+ " date " : date,
82
+ " repeating " : repeating
83
+ ]
84
+ case . interval( let interval) :
85
+ return [
86
+ " type " : " interval " ,
87
+ " interval " : scheduleIntervalToDictionary ( interval)
88
+ ]
89
+ case . every( let interval, let count) :
90
+ return [
91
+ " type " : " every " ,
92
+ " interval " : interval. rawValue,
93
+ " count " : count
94
+ ]
95
+ }
96
+ }
97
+
98
+ func scheduleIntervalToDictionary( _ interval: ScheduleInterval ) -> [ String : Any ] {
99
+ var dict : [ String : Any ] = [ : ]
100
+
101
+ if let year = interval. year {
102
+ dict [ " year " ] = year
103
+ }
104
+ if let month = interval. month {
105
+ dict [ " month " ] = month
106
+ }
107
+ if let day = interval. day {
108
+ dict [ " day " ] = day
109
+ }
110
+ if let weekday = interval. weekday {
111
+ dict [ " weekday " ] = weekday
112
+ }
113
+ if let hour = interval. hour {
114
+ dict [ " hour " ] = hour
115
+ }
116
+ if let minute = interval. minute {
117
+ dict [ " minute " ] = minute
118
+ }
119
+ if let second = interval. second {
120
+ dict [ " second " ] = second
121
+ }
122
+
123
+ return dict
124
+ }
125
+
69
126
func makeAttachments( _ attachments: [ NotificationAttachment ] ) throws -> [ UNNotificationAttachment ] {
70
127
var createdAttachments = [ UNNotificationAttachment] ( )
71
128
0 commit comments