As of now i get the push notifications and displaying the banner when im in both foreground and background states. But though its works fine in the background, when I'm in foreground im unable to trigger an action to open a specific view controller once i click the banner (should open only if i click the banner). How would i do this. My code as bellow
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
{
print("Recived: \(userInfo)")
completionHandler(.newData)
if state == .background {
if mediaId != nil{
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mP3ViewController = storyboard.instantiateViewController(withIdentifier:"MP3ViewController") as! MP3ViewController
mP3ViewController.media_ID = mediaId
self.navigationController?.pushViewController(mP3ViewController, animated:true)
}
}
}else if state == .active {
//What sould i do here to get the click
print("Running on foreground")
UIApplication.shared.applicationIconBadgeNumber = 0
let count = 0
UserDefaults.standard.setValue(count, forKey: "PUSH_COUNT")
UserDefaults.standard.synchronize()
}
}