I implemented a function to open an AlertView when I receive a remote notification like this:
func application(application: UIApplication, didReceiveRemoteNo
Method (Swift 4):
func extractUserInfo(userInfo: [AnyHashable : Any]) -> (title: String, body: String) {
var info = (title: "", body: "")
guard let aps = userInfo["aps"] as? [String: Any] else { return info }
guard let alert = aps["alert"] as? [String: Any] else { return info }
let title = alert["title"] as? String ?? ""
let body = alert["body"] as? String ?? ""
info = (title: title, body: body)
return info
}
Usage:
let info = self.extractUserInfo(userInfo: userInfo)
print(info.title)
print(info.body)