I'm trying to add badges to my app icon when GameCenter provides a notification from a GKTurnBasedMatch.
There isn't much information about how to do this. One old post suggests implementing an AppDelegate method: https://developer.apple.com/forums/thread/54056
Since my project is in SwiftUI, I tried creating a UIApplicationDelegateAdaptor to support an AppDelegate, and implementing the func application(: didFinishLaunchingWithOptions:) method as follows, attempting to update it to support the newer notification object:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
application.registerForRemoteNotifications()
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) { success, error in
// not sure what to do here
}
return true
}
This method does seem to get called when the app opens, but badges still do not appear on my app's icon.