- Open the same demo project and click on the AppDelegate.swift file.
- The first thing that we will do is enable the presentable of Push Notification if the app is in foreground and handle the tapping of the Push Notifications.
- Update the function of registerForPushNotifications to be like the following:
func registerForPushNotifications(){ let application = UIApplication.shared let center = UNUserNotificationCenter.current() center.delegate = self center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in // actions based on whether notifications were authorized or not print(granted) print(error ?? "No error") } application.registerForRemoteNotifications() }
- At the end of the file, add the following extension ...