0
0
iOS Swiftmobile~10 mins

Local notifications in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to request permission for local notifications.

iOS Swift
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
    if granted {
        print("Permission [1]")
    }
}
Drag options to blanks, or click blank then click option'
Adenied
Bgranted
Crequested
Dpending
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'granted' with 'denied'.
Using words unrelated to permission status.
2fill in blank
medium

Complete the code to create a notification content with a title.

iOS Swift
let content = UNMutableNotificationContent()
content.[1] = "Hello!"
Drag options to blanks, or click blank then click option'
Atitle
Bbody
Csubtitle
Dsound
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'body' instead of 'title' for the main heading.
Confusing 'subtitle' with 'title'.
3fill in blank
hard

Fix the error in the code to schedule a notification after 5 seconds.

iOS Swift
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: [1], repeats: false)
let request = UNNotificationRequest(identifier: "test", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
Drag options to blanks, or click blank then click option'
A5
B-5
C0
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative values causes errors.
Using too large a number delays notification too long.
4fill in blank
hard

Fill both blanks to create a notification with a badge number and sound.

iOS Swift
content.[1] = 1
content.[2] = UNNotificationSound.default
Drag options to blanks, or click blank then click option'
Abadge
Btitle
Csound
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'title' or 'body' with badge or sound properties.
Using wrong property names for badge or sound.
5fill in blank
hard

Fill all three blanks to create and schedule a notification with a 10-second delay and a custom identifier.

iOS Swift
let content = UNMutableNotificationContent()
content.title = "Reminder"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: [1], repeats: [2])
let request = UNNotificationRequest(identifier: [3], content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
Drag options to blanks, or click blank then click option'
Afalse
B10
C"reminder_01"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting repeats to true causes repeated notifications.
Using a number instead of a string for identifier.
Using wrong time interval values.