In order to try out Push Notifications with Firebase I am following this example: https://github.com/firebase/quickstart-ios/blob/dc2cd2db6e82e5c475fa3f0efe75df8b54f04544/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55
I could make it work up to a certain point.
Here is the relevant code I have:
......
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
......
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
application.registerForRemoteNotifications()
FirebaseApp.configure()
......
return true
}
......
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
print(#function)
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
completionHandler()
}
......
When I try to test it, the function userNotificationCenter:didReceive:withCompletionHandler() is the only one called (in the list of function provided by the example). It should also be noticed that I can see this looking at the debugger console and nothing is happening on the device. I guess that's the way it's supposed to be (so all is fine), but here is a question I have for anyone who can answer.
How do I make use of completionHandler() ? I suppose, since it's a parameter I can make some use of it in a rather free way, but when I look for sample code on the net I can only see it declared in the list of parameters or called as is the case in the example I am working with, but I never see it defined.
Is there something I should look at or a concrete example of how to make use of it?
For information, I am using Xcode Version 10.1, iOS 12.1 and Swift 4.2.