Complete action: https://www.raywenderlich.com/8164-push-notifications-tutorial-getting-started

Permission Settings

  1. Enable Push Notif in Capabilities in XCode
  2. Check Certificate, Identifiers, and Profiles in Developer Account
  3. import UserNotifications in AppDelegate
  4. Add registerForPushNotifications() method in AppDelegate before close bracket
func registerForPushNotifications() {
	UNUserNotificationCenter.current() // 1
	.requestAuthorization(options: [.alert, .sound, .badge]) { // 2
		granted, error in
		print("Permission granted: \\(granted)") // 3
	}
}
  1. Add the following near the end of application(_:didFinishLaunchingWithOptions:), just before the return:

registerForPushNotifications()

  1. Add getNotificationSettings() method inside AppDelegate
func getNotificationSettings() {
	UNUserNotificationCenter.current().getNotificationSettings { settings in
		print("Notification settings: \\(settings)")
	}
}
  1. In registerForPushNotifications, replace the call to requestAuthorization(options:completionHandler:) with the following:
UNUserNotificationCenter.current()
.requestAuthorization(options: [.alert, .sound, .badge]) {
	[weak self] granted, error in
	print("Permission granted: \\(granted)")
	guard granted else { return }
	self?.getNotificationSettings()
}

Registering APNs

  1. In getNotificationSettings(), add the following beneath the print inside the closure:

guard settings.authorizationStatus == .authorized else { return }

DispatchQueue.main.async {

UIApplication.shared.registerForRemoteNotifications()

}