Hey Anton,
Sorry for the late reply. This is how we have setup this particular app notification. Please advise if there is something we’ve done wrong.
AppDelegate.swift:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void){
if response.actionIdentifier == “Notification_ok” {
let alertController = UIAlertController(title: “Confirmation”,
message: “Ok”,
preferredStyle: .alert)
let defaultAction = UIAlertAction(title: “Cancel”, style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
}
alertController.addAction(defaultAction)
}
else if response.actionIdentifier == “Notification_confirm”{
let application = UIApplication.shared
if application.applicationState == UIApplicationState.active{
UserDefaults.standard.set(“0”, forKey: “isFromNotification”)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: “deleteBooking”), object:“0”, userInfo:response.notification.request.content.userInfo)
}else{
UserDefaults.standard.set(“0”, forKey: “isFromNotification”)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: “deleteBooking”), object:“1”, userInfo:response.notification.request.content.userInfo)
}
}else
{
}
completionHandler()
}
LoggedinViewController:
func handleModifyListNotification(_ notification:Notification)
{
var dicInfo = notification.userInfo! as Dictionary
let pkName = dicInfo[“parkName”] as! String
let pkTime = dicInfo[“time”] as! String
let objId = dicInfo[“objectId”] as! String
if notification.object as! String == "1" {
self.deleteBooking(objId)
}
else
{
let alertController = UIAlertController(title: "Confirmation",
message: "Are You Still going to the \(pkName) at \(pkTime)?",
preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
self.deleteBooking(objId)
}
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
}
alertController.addAction(defaultAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
}
}
func handleShowPopUp(_ tmpDic:NSDictionary)
{
let APPDelegate = UIApplication.shared.delegate as! AppDelegate
APPDelegate.isFromNotication = false
let pkName = tmpDic["parkName"] as! String
let pkTime = tmpDic["time"] as! String
let objId = tmpDic["objectId"] as! String
DispatchQueue.main.async
{
let alertController = UIAlertController(title: "Confirmation",
message: "Are You Still going to the \(pkName) at \(pkTime)?",
preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
self.deleteBooking(objId)
}
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
}
alertController.addAction(defaultAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
}
}