Starting with the basics
Let's begin by getting our app to send us basic notifications. Inside our restaurant details page, we have three buttons (9:30PM, 10:00PM, and 10:30PM) that currently do not do anything. We are going to update these buttons so that when you tap on one of them, it will create a restaurant reservation notification. If this were a real reservations app, we would want to store these reservations. When the reservation date and time neared, we would then post a notification to the user as a reminder. Doing all of that is out of the scope of this book, so we will just address creating a restaurant reservation notification.
Getting permission
Before we can send any notifications, we must get the user's permission. Therefore, open the AppDelegate.swift
file and add the following method after the didFinishLaunchingWithOptions()
method:
func checkNotifications() { UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (isGranted...