Starting from:

$29

Homework 7 adding an alert to confirm deletion


School of Electrical Engineering and Computer Science

CptS 479 Mobile Application Development
Homework 7

General Instructions: Put the entire app directory into one zip file and submit as an attachment
under Content → Assignments → Homework 7 for this course on Blackboard Learn by the above
deadline. Note that you may submit multiple times, but only the most recent entry submitted before
the above deadline will be graded.
This homework builds on HW5
1 or HW6 (your choice) by adding an alert to confirm deletion and
adding the ability to choose a quotation for a “Quote of the Day” notification. See screen shots
below. Specifically,
1. Ensure your app has all HW5 capabilities, including a table view to list and delete the
quotations, an add quotation view to add quotations, and a detail view to view the quotation
details. You can still use HW6 if you want, but we will not be accessing the settings view
or changing any of the device settings.
2. Implement an alert that is triggered when you attempt to delete a table entry. After tapping
Delete in the row, an alert should appear with title “Delete Quotation?” and the message
set to the quote to be deleted. The two actions should be “Delete” with .destructive style,
and “Cancel” with .cancel style. Tapping Cancel should do nothing, and tapping Delete
should proceed to delete the table row.
3. For the notification, we will need to uniquely identify each quotation with a string ID that
is passed in the userInfo dictionary of the notification and then back to the app when the
user taps the notification. So, add the new property “id” to the Quotation class of type
String. In the init method, set this “id” to “UUID().uuidString”. This is guaranteed to
generate a unique identifier each time.
4. In the AppDelegate (or the SceneDelegate) request authorization to schedule notifications.
When the app starts up, we will always choose “Allow”, but we will late disable
notifications inside the device settings to check that you handle this case.
5. On the quotation detail view controller, center a button titled “Schedule Notification”
underneath the author label. When tapped, the app should first check that notifications are
still allowed, and if so, schedule a notification with title “Quote of the Day” and the body
set to the quote. You should also set the userInfo[“id”] dictionary entry to the quotation’s
1 My solution to HW5 is available on Blackboard Learn. You may use it as a starting point for this
homework.
2
“id”. Set the notification to trigger five seconds after adding it, and then add it to the
UserNotificationCenter.
6. Add a handleNotification method to the main quotation table view controller. This method
should extract the quotation id from the userInfo dictionary, set a class variable (e.g.,
quoteOfTheDayID) to this id, and reload the table. If this quotation is still in the table, its
quote should be displayed in red. All other quotes, even ones previously colored red, should
be reset back to the default color.
7. Next, you need to call this handleNotification method when the app returns to the
foreground (after the user taps the notification) by implementing the didReceive method of
the UNUserNotificationCenterDelegate. Since we don’t know which view is currently the
top view controller on the navigation stack, we will search through them all to find the
main quotation table view controller and then call its handleNotification method. Below is
a code snippet for doing this inside didReceive in the AppDelegate, assuming the main
quotation table view controller is of type QuotationTableViewController.
8. Test your app using the iPhone 11 simulator, which is the same simulator we will use to
grade your app.
9. Be sure that auto layout constraints are set so that all view elements are appropriately
displayed with no overlap or trimming regardless of device orientation.
let navVC = UIApplication.shared.windows.first!.rootViewController
as! UINavigationController
let vcs = navVC.viewControllers
for vc in vcs {
if let mainVC = vc as? QuotationTableViewController {
mainVC.handleNotification(response)
}
}
3
Storyboard (based on HW5):
4
Simulator (just showing new HW7 capabilities):

More products