In an iOS undertaking, I’ve carried out the next delegate technique to deal with Notifications when app is in foregorund:
func userNotificationCenter (_ pNotificationCenter : UNUserNotificationCenter, willPresent pNotification : UNNotification, withCompletionHandler /CompletionHandler : @escaping (UNNotificationPresentationOptions) -> Void) -> Void
{
// When app is in foreground, notification is straight despatched to
// the app by invoking this delegate technique.
}
Often, this warning means a easy spelling error which causes the compiler to get confused with the tactic specification in protocol. However I’ve verified all that from the documentation.
Out of curiosity, I wished to verify what Xcode suggests… and it is the next delegate technique.
func userNotificationCenter(_ heart: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (Int) -> Void) {
}
Discover the Int
parameter within the escaping closure. However that is flawed, proper? The Apple documentation (linked above) explicitly states the escaping closure’s parameter is UNNotificationPresentationOptions
. And UNNotificationPresentationOptions
will not be an enum (it is a struct), so the closure can not take Int
, but Xcode advised it.
Xcode additionally gave the next suggestion:
Make 'userNotificationCenter(_:willPresent:withCompletionHandler:)' non-public to silence this warning
however why? I’ve carried out the appropriate delegate technique. How can I repair this warning?