my appDelegate has a the following:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let dictPayload = userInfo as NSDictionary
if let data = dictPayload.value(forKey: "aps") as? NSDictionary {
let link = data.value(forKey: "Link") as? String
print("link: \(link!)")
UserDefaults.standard.set(link, forKey: "link_from_push")
UserDefaults.standard.synchronize()
UserDefaults.standard.set("open_link", forKey: "push_action")
UserDefaults.standard.synchronize()
}
print("Push notification received: \(userInfo)")
}
I can see the flow of information through Xcode. Now I want to pop an alert if app is open and in the foreground, no matter which view the user is on at the moment.
the following function is used from appDelegate:
let topWindow = UIWindow(frame: UIScreen.main.bounds)
topWindow.rootViewController = UIViewController()
topWindow.windowLevel = UIWindowLevelAlert + 1
let alert = UIAlertController(title: "APNS", message: "received Notification", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "confirm"), style: .cancel, handler: {(_ action: UIAlertAction) -> Void in
// continue your work
// important to hide the window after work completed.
// this also keeps a reference to the window until the action is invoked.
topWindow.isHidden = true
}))
topWindow.makeKeyAndVisible()
topWindow.rootViewController?.present(alert, animated: true, completion: { _ in })
Which works fine but I need to add another action button.
Any help will be greatly appreciated