ReviewOS

also looking at this

craft-native/craft

feat(ios): tell the page about a notification that arrives while the app is open

#259
Merged glennmichael123 wants to merge feat/ios-notification-received into main
11 files +410 -58
packages/ios/src/index.test.tsmodified+17-0
Changes to packages/ios/src/index.test.ts
@@ -376,6 +376,23 @@ describe('Craft iOS builder', () => {
376376 expect(handle.slice(0, handle.indexOf('\n }\n'))).toContain('sendToWeb("craftNotificationResponse"')
377377 })
378378
379 it('tells the page about a notification that arrives while the app is open', async () => {
380 // willPresent used to show the banner and nothing else, so a page on
381 // screen when a push landed heard about it only if someone tapped it.
382 const output = mkdtempSync(join(tmpdir(), 'craft-ios-notification-received-'))
383 await init({ name: 'WildLoop', bundleId: 'org.wildloop.app', output })
384 const swift = readFileSync(join(output, 'Sources', 'WildLoopApp.swift'), 'utf8')
385
386 const willPresent = swift.slice(swift.indexOf('willPresent notification: UNNotification'))
387 const body = willPresent.slice(0, willPresent.indexOf('\n }\n'))
388 expect(body).toContain('CraftEventManager.shared.handleNotificationReceived(notification.request.content.userInfo)')
389 // Told, not asked: the banner still shows.
390 expect(body).toContain('completionHandler([.banner, .badge, .sound])')
391
392 const handle = swift.slice(swift.indexOf('func handleNotificationReceived('))
393 expect(handle.slice(0, handle.indexOf('\n }\n'))).toContain('sendToWeb("craftNotificationReceived"')
394 })
395
379396 it('settles calendar callbacks only after a real EventKit operation', async () => {
380397 const output = mkdtempSync(join(tmpdir(), 'craft-ios-calendar-'))
381398 await init({