Closed TheDagger closed 7 years ago
Finally found answer, hope this is how you intended it
// Push notification received
func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
// Print notification payload data
print("Push notification received: \(data)")
let aps = data[AnyHashable("aps")]! as! NSDictionary
let alert = aps["alert"]! as! NSDictionary
let body = alert["body"] as! String
let title = alert["title"] as! String
print("body=\(body)")
print("title=\(title)")
}
This question is not really PushOK related, more Swift/iOS/APNS related. You should close this issue.
// Push notification received func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) { // Print notification payload data print("Push notification received: (data)")
let aps = data[AnyHashable("aps")]! as! NSDictionary
let alert = aps["alert"]! as AnyObject as! NSDictionary
print("alert=\(alert)")
let body = alert["body"] as AnyObject as! NSDictionary
if let content_type = body["content_type"] as? String {
print("content_type is : \(content_type)")
}
if let information = body["information"] as? String {
print("information is : \(information)")
}
if let title = alert["title"] as? String {
print("title is : \(title)")
}
}
I have this code when I get the push notification, push notifications work by the way.
Here is the console output...
How do I get access to the variables in the alert object in Swift3?