You need to implement UserNotifications in AppDelegate .
import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
And then use the following code inside didFinishLaunchingWithOptions :
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in if error != nil {
Here you can find many important materials in the notification topic.
For the badge:
let content = UNMutableNotificationContent() content.badge = 10
source share