NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Where to call NotificationCenter.default.addObserver() ? in my Xcode Game Project

Forums > iOS

Where to call NotificationCenter.default.addObserver() ? in my Xcode Game Project

I successfully call the following from my func application (AppDelegate), but when I toggle the Gamepad on/off, my selectors are not being called.

class GameScene: SKScene {

    func ObserveForGameControllers() {

    //  print("ObserveForGameControllers")

                    selector: #selector(connectControllers),
                    name: NSNotification.Name.GCControllerDidConnect,
                    object: nil)

                    selector: #selector(disconnectControllers),
                    name: NSNotification.Name.GCControllerDidDisconnect,
                    object: nil)

    }   // ObserveForGameControllers


My selectors look like this:

@objc func connectControllers() {}
@objc func disconnectControllers() {}

Someone recommended I call ObserveForGameControllers() from my class GameScene, like so

override func sceneDidLoad() {



}   // sceneDidLoad

but that did not work at all.

One last thing:

Here are my Gamepad settings in my Project

It seems I really need some suggestions here.

Appreciate it.


Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until October 1st.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.