My push data is
{
"aps" : {
"alert" : {
"id" : 2091
},
"sound" : "chime.aiff"
},
"acme" : "foo"
}
I have used id because i can separate each push by its id, and based on id i can decide weather to show notification in foreground or not..
Thanks @Anbu.Karthik For reference
as per my question we can handle push even user did't tap on notification in
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
print("Handle push from foreground")
let userInfo:[AnyHashable:Any] = notification.request.content.userInfo
let aps:NSDictionary = (userInfo[AnyHashable("aps")] as? NSDictionary)!
let alert:NSDictionary = (aps["alert"] as? NSDictionary)!
let id = Int(alert["id"] as! Int)
if id == your id
{
//Handle push without prompting alert
}
else
{
//Display alert
completionHandler(UNNotificationPresentationOptions.alert)
}
}
And When user tap on notification Following method is called...
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print(userInfo)
}