@@ -169,6 +169,7 @@ class MyUserNotificationHelper : NSObject {
169
169
content. sound = UNNotificationSound . default
170
170
content. sound = UNNotificationSound ( named: UNNotificationSoundName ( " test.aif " ) )
171
171
content. badge = 20
172
+ content. userInfo [ " scheduled " ] = Date ( )
172
173
173
174
// if we want to see actions, we must add category identifier
174
175
content. categoryIdentifier = self . categoryIdentifier
@@ -204,16 +205,24 @@ class MyUserNotificationHelper : NSObject {
204
205
let center = UNUserNotificationCenter . current ( )
205
206
center. add ( req)
206
207
207
- // test nextTriggerDate bug
208
+ // test nextTriggerDate bug; keep app running if you want to see this
208
209
print ( " scheduling at " , Date ( ) )
210
+ print ( " time trigger is " , trigger. timeInterval)
209
211
DispatchQueue . main. asyncAfter ( deadline: . now( ) + 5 ) {
210
212
print ( " checking at " , Date ( ) )
211
213
UNUserNotificationCenter . current ( ) . getPendingNotificationRequests {
212
214
arr in let arr = arr
213
215
guard arr. count > 0 else { print ( " no pending requests " ) ; return }
214
- if let req = arr [ 0 ] . trigger as? UNTimeIntervalNotificationTrigger {
215
- let fd = req. nextTriggerDate ( )
216
+ let req = arr [ 0 ]
217
+ if let trig = req. trigger as? UNTimeIntervalNotificationTrigger {
218
+ let fd = trig. nextTriggerDate ( )
216
219
print ( " trigger date " , fd as Any )
220
+ if let d = req. content. userInfo [ " scheduled " ] as? Date {
221
+ print ( " but it was scheduled at " , d)
222
+ print ( " with a time interval of " , trig. timeInterval)
223
+ }
224
+ } else {
225
+ print ( " no time interval trigger " )
217
226
}
218
227
}
219
228
}
@@ -236,9 +245,13 @@ extension MyUserNotificationHelper : UNUserNotificationCenterDelegate {
236
245
237
246
print ( " received notification while active " , Date ( ) )
238
247
239
- // NB in iOS 14, alert is replaced by banner here
240
- completionHandler ( [ . sound, . banner] ) // go for it, system!
241
- // completionHandler([])
248
+ var ok : Bool { true }
249
+ if ok {
250
+ // NB in iOS 14, alert is replaced by banner here
251
+ completionHandler ( [ . sound, . banner] ) // go for it, system!
252
+ } else {
253
+ completionHandler ( [ ] )
254
+ }
242
255
243
256
// oooh oooh I accidentally learned something
244
257
// if Do Not Disturb is on, no notifications interrupt
0 commit comments