func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
startSavingNotification(userInfo: userInfo)
completionHandler(UIBackgroundFetchResult.newData)
//TODO: TEST
//showTestPushAlert(userInfo: userInfo)
}
//Fire Test notification
func startSavingNotification(userInfo:[AnyHashable : Any]) {
//Fetch Payload Dict
if let payloadDict = userInfo["payload"] as? Dictionary<String,Any> {
savePushNotification(payloadDict: payloadDict)
}
}
func showTestPushAlert(userInfo:[AnyHashable : Any]) {
let alert = UIAlertController(title:"", message: "\(userInfo)", preferredStyle: .alert)
let cancelButton = UIAlertAction(title: "Ok", style: .cancel, handler: nil)
alert.addAction(cancelButton)
UIApplication.topViewController()?.present(alert, animated: true, completion: nil)
}
When i try to show data in alert then this userinfo looks like this way :
Here above line if condition is getting false , do something wrong here :?? if let payloadDict = userInfo["payload"] as? Dictionary { savePushNotification(payloadDict: payloadDict) }