Hi, I am working on an app and I need it to call my pauseAfterNotif() method whenever the user receives a push notification (text message, instagram dm, etc.)
Here's what I have right now:
AppDelegate:
func applicationWillResignActive(_ application: UIApplication) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "goToBackground"), object: self)
print("notif read")
}
GameScene.didMove():
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(pauseAfterNotif), name: UIApplication.willResignActiveNotification, object: nil)
GameScene.pauseAfterNotif():
@objc func pauseAfterNotif() {
if !isGamePaused {
pauseGame()
print("notif detected")
}
}
Right now, the code only executes when I exit the game and enter the homescreen or if I receive a call while playing. Is it possible to have it execute when I receive a push notification too?