Skip to content

Commit 71eed62

Browse files
committed
remove today extension; clarify local notification trigger date bug; improvements to activity view example
1 parent 7b4fe30 commit 71eed62

File tree

23 files changed

+32
-1052
lines changed

23 files changed

+32
-1052
lines changed

bk2ch13p630localNotification/ch26p899localNotification/ViewController.swift

+19-6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class MyUserNotificationHelper : NSObject {
169169
content.sound = UNNotificationSound.default
170170
content.sound = UNNotificationSound(named: UNNotificationSoundName("test.aif"))
171171
content.badge = 20
172+
content.userInfo["scheduled"] = Date()
172173

173174
// if we want to see actions, we must add category identifier
174175
content.categoryIdentifier = self.categoryIdentifier
@@ -204,16 +205,24 @@ class MyUserNotificationHelper : NSObject {
204205
let center = UNUserNotificationCenter.current()
205206
center.add(req)
206207

207-
// test nextTriggerDate bug
208+
// test nextTriggerDate bug; keep app running if you want to see this
208209
print("scheduling at", Date())
210+
print("time trigger is", trigger.timeInterval)
209211
DispatchQueue.main.asyncAfter(deadline: .now()+5) {
210212
print("checking at", Date())
211213
UNUserNotificationCenter.current().getPendingNotificationRequests {
212214
arr in let arr = arr
213215
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()
216219
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")
217226
}
218227
}
219228
}
@@ -236,9 +245,13 @@ extension MyUserNotificationHelper : UNUserNotificationCenterDelegate {
236245

237246
print("received notification while active", Date())
238247

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+
}
242255

243256
// oooh oooh I accidentally learned something
244257
// if Do Not Disturb is on, no notifications interrupt

bk2ch13p631todayExtension/CoffeeTimeTodayExtension/CoffeeTimeToday.storyboard

-88
This file was deleted.

bk2ch13p631todayExtension/CoffeeTimeTodayExtension/Info.plist

-33
This file was deleted.

bk2ch13p631todayExtension/CoffeeTimeTodayExtension/TodayViewController.swift

-96
This file was deleted.
Binary file not shown.
Binary file not shown.

bk2ch13p631todayExtension/TestTodayExtension/AppDelegate.swift

-71
This file was deleted.

0 commit comments

Comments
 (0)