I m build ios application using swift 5. I config the app to receive push message using firebase.
Now I m able to see push message, but I m not able to show only the information that I need on push message.
This is the code in my appdelegate
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
print("willPresent \(userInfo)")
Messaging.messaging().appDidReceiveMessage(userInfo)
/*if let info = userInfo as? Dictionary<String, AnyObject> {
let title = userInfo["google.c.a.c_l"] as! String
hanleNotification(info: info, strStatus: title, strFrom: "Front")
}*/
completionHandler([[.alert, .sound]])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
print("Did Recceive \(userInfo)")
if let info = userInfo as? Dictionary<String, AnyObject> {
//let alert1 = info["aps"]!["alert"] as! Dictionary<String, AnyObject>
let title = userInfo["aps"] as! JSON
hanleNotification(info: info, strStatus: "titolo", strFrom: "Back")
}
//Messaging.messaging().appDidReceiveMessage(userInfo)
completionHandler()
}
//MARK:GoViewCotroller
func hanleNotification(info:Dictionary<String,AnyObject>,strStatus:String,strFrom:String) {
let visibleVC = UIApplication.topViewController()
if strStatus == "join_live_session" || strStatus == "exist_session" || strStatus == "join_request" {
}
}
THe method print this message on my xcode console:
willPresent [AnyHashable("gcm.notification.vibrate"): 1, AnyHashable("aps"): {
alert = {
body = "{\"result\":\"successful\",\"msg\":\"speranza4\",\"date\":\"2021-10-07 06:29:50\",\"italian_msg\":\"Hai un nuovo messaggio\",\"user_id\":\"30\",\"chat_image\":null,\"order_id\":\"\",\"key\":\"You have a new message\",\"status\":\"chat\",\"username\":\"Michele\"}";
title = ArrivaArriva;
};
sound = 1;
}
I need to use italian_message as body of message.