Challenge - 5 Problems
Local Notifications Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when this local notification code runs?
Consider this Swift code snippet scheduling a local notification. What will the user see after 5 seconds?
iOS Swift
import UserNotifications let center = UNUserNotificationCenter.current() let content = UNMutableNotificationContent() content.title = "Reminder" content.body = "Time to check the app!" let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) let request = UNNotificationRequest(identifier: "reminder1", content: content, trigger: trigger) center.add(request) { _ in }
Attempts:
2 left
💡 Hint
Think about what UNTimeIntervalNotificationTrigger does with the timeInterval parameter.
✗ Incorrect
The code schedules a local notification to appear after 5 seconds with the specified title and body. The sound is optional and defaults to no sound if not set. The trigger waits the specified time before showing the notification.
❓ lifecycle
intermediate2:00remaining
When should you request permission for local notifications?
In an iOS app, when is the best time to ask the user for permission to send local notifications?
Attempts:
2 left
💡 Hint
Consider user experience and when the user expects notifications.
✗ Incorrect
Requesting permission only when needed improves user trust and avoids annoying prompts. Local notifications require user permission.
🔧 Debug
advanced2:00remaining
Why does this local notification never appear?
This Swift code schedules a notification but it never shows. What is the cause?
iOS Swift
let content = UNMutableNotificationContent() content.title = "Alert" content.body = "Check this out!" let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false) let request = UNNotificationRequest(identifier: "alert1", content: content, trigger: trigger) UNUserNotificationCenter.current().add(request) { _ in }
Attempts:
2 left
💡 Hint
Check the trigger’s timeInterval value requirements.
✗ Incorrect
UNTimeIntervalNotificationTrigger requires timeInterval to be greater than 0. Zero causes the notification not to schedule.
🧠 Conceptual
advanced2:00remaining
What is the role of UNNotificationRequest in local notifications?
Which best describes the purpose of UNNotificationRequest in iOS local notifications?
Attempts:
2 left
💡 Hint
Think about what you need to schedule a notification.
✗ Incorrect
UNNotificationRequest packages the content and trigger together so the system knows what to show and when.
expert
2:00remaining
How to handle user tapping a local notification to navigate?
When a user taps a local notification, how can your app navigate to a specific screen?
Attempts:
2 left
💡 Hint
Look for delegate methods related to notification responses.
✗ Incorrect
The delegate method userNotificationCenter(_:didReceive:withCompletionHandler:) is called when the user taps a notification, allowing navigation logic.