Notifications and ViewControllers

Hi, I am trying to make it so that my notification opens up the “The Riddle” View controller, but I can’t figure out how. Here is a link: https://www.icloud.com/iclouddrive/0PDX_ZK3kyamqHjV8-hlDhZbw#Riddle_Wednesday

Thanks in advance!
Please copy the relevant part of code as well, don't force us to go and inspect a whole code.
AppDelegate:
Code Block //
import UIKit
import Firebase
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        return true
    }
    // MARK: UISceneSession Lifecycle
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
}

TheRiddle ViewController:

Code Block import UIKit
import SafariServices
import WebKit
import Firebase
class TheRiddle: UIViewController {
    
    @IBOutlet weak var leading_TheRiddle: NSLayoutConstraint!
    @IBOutlet weak var trailing_TheRiddle: NSLayoutConstraint!
    
    @IBOutlet weak var CurrentRiddle: UILabel!
    @IBOutlet weak var PreviousRiddle: UILabel!
    
    var menuOut = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let db = Firestore.firestore()
        
        db.collection("TheRiddle").document("Riddles").getDocument { (document, error) in
            
            //check for error
            if error == nil {
                //check if document exists
                if document != nil {
                }else {
                    if let currentRiddle = document!.get("CurrentRiddle") as? String {
                        self.CurrentRiddle.text = "This Weeks Riddle: " + currentRiddle
                    }
                    if let previousRiddle = document!.get("CurrentRiddle") as? String {
                        self.CurrentRiddle.text = "Previous Riddle: " + previousRiddle
                    }
                }
            }
            
        }
        
        
    }
    
    
    @IBAction func RiddleAnswerForm(_ sender: Any) {
        let vc = SFSafariViewController(url: URL(string: "https://forms.office.com/Pages/ResponsePage.aspx?id=ytAqTDte6UK-KD5v_kOm4Y843IzqmYtFlDtLrfRYsi1UMFpUMk1GN01GS05BVFlJUElONk4yR1hKUCQlQCN0PWcu")!)
        
        present(vc, animated: true)
    }
    
    @IBAction func menuTappedTheRiddle(_ sender: Any) {
        
        if menuOut == false {
            leading_TheRiddle.constant = 150
            trailing_TheRiddle.constant = -150
            menuOut = true
        }
        else {
            leading_TheRiddle.constant = 0
            trailing_TheRiddle.constant = 0
            menuOut = false
        }
        UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
            self.view.layoutIfNeeded()
        }) { (animationComplete) in
            print("The animation is complete")
        }
}
}


First, I formatted your code to make it easier to grasp.
I see nowhere any reference to notification.

How do you want to open ?
  • when user taps the notification ?

  • other ?

What is it more specifically you don't know how to do ?

For User Notification, I advise to read first this tutorial, which explain the whole process from registering to processing notification.
https ://www.raywenderlich. com/11395893-push-notifications-tutorial-getting-started

Code Block
import UIKit
import Firebase
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
}
// TheRiddle ViewController:
import UIKit
import SafariServices
import WebKit
import Firebase
class TheRiddle: UIViewController {
@IBOutlet weak var leading_TheRiddle: NSLayoutConstraint!
@IBOutlet weak var trailing_TheRiddle: NSLayoutConstraint!
@IBOutlet weak var CurrentRiddle: UILabel!
@IBOutlet weak var PreviousRiddle: UILabel!
var menuOut = false
override func viewDidLoad() {
super.viewDidLoad()
let db = Firestore.firestore()
db.collection("TheRiddle").document("Riddles").getDocument { (document, error) in
//check for error
if error == nil {
//check if document exists
if document != nil {
} else {
if let currentRiddle = document!.get("CurrentRiddle") as? String {
self.CurrentRiddle.text = "This Weeks Riddle: " + currentRiddle
}
if let previousRiddle = document!.get("CurrentRiddle") as? String {
self.CurrentRiddle.text = "Previous Riddle: " + previousRiddle
}
}
}
}
}
@IBAction func RiddleAnswerForm(_ sender: Any) {
let vc = SFSafariViewController(url: URL(string: "https://forms.office.com/Pages/ResponsePage.aspx?id=ytAqTDte6UK-KD5v_kOm4Y843IzqmYtFlDtLrfRYsi1UMFpUMk1GN01GS05BVFlJUElONk4yR1hKUCQlQCN0PWcu")!)
present(vc, animated: true)
}
@IBAction func menuTappedTheRiddle(_ sender: Any) {
if menuOut == false {
leading_TheRiddle.constant = 150
trailing_TheRiddle.constant = -150
menuOut = true
}
else {
leading_TheRiddle.constant = 0
trailing_TheRiddle.constant = 0
menuOut = false
}
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
self.view.layoutIfNeeded()
}) { (animationComplete) in
print("The animation is complete")
}
}
}


Thank you so much. Will check out the tutorial.
OK. Please tell if you have any problem implementing. Otherwise, don't forget to close the thread on the correct answer.
Notifications and ViewControllers
 
 
Q