Reputation: 845
In an iOS project, I have implemented the following delegate method to handle Notifications when app is in foregorund:
func userNotificationCenter (_ pNotificationCenter : UNUserNotificationCenter, willPresent pNotification : UNNotification, withCompletionHandler pCompletionHandler : @escaping (UNNotificationPresentationOptions) -> Void) -> Void
{
// When app is in foreground, notification is directly sent to
// the app by invoking this delegate method.
}
Usually, this warning means a simple spelling error which causes the compiler to get confused with the method specification in protocol. But I've verified all that from the documentation.
Out of curiosity, I wanted to check what Xcode suggests... and it's the following delegate method.
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (Int) -> Void) {
}
Notice the Int
parameter in the escaping closure. But this is wrong, right? The Apple documentation (linked above) explicitly states the escaping closure's parameter is UNNotificationPresentationOptions
. And UNNotificationPresentationOptions
is not an enum (it's a struct), so the closure cannot take Int
, yet Xcode suggested it.
Xcode also gave the following suggestion:
Make 'userNotificationCenter(_:willPresent:withCompletionHandler:)' private to silence this warning
but why? I have implemented the right delegate method. How can I fix this warning?
Edit1: Here's a google drive link which has a tiny version of the Xcode project I'm working on. After downloading the zip file, please follow the steps to setup and reproduce the warning:
Upvotes: 0
Views: 408
Reputation: 21
completionHandler(Int(UNNotificationPresentationOptions.banner.rawValue))
Upvotes: 0