I implemented a function to open an AlertView when I receive a remote notification like this:
func application(application: UIApplication, didReceiveRemoteNo
Alert should be showing while the app is in active state. So check the state is active or not.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if application.applicationState == .active {
if let aps = userInfo["aps"] as? NSDictionary {
if let alertMessage = aps["alert"] as? String {
let alert = UIAlertController(title: "Notification", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(action)
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
}
}
}
completionHandler(.newData)
}
From this if a user need message then he can get alert message.