How to access the currently active iOS screen?

Hello,

With NotificationCenter added to my iOS device I can request a token for remote notifications.The event RemoteRegistrationSucceeded() get called with a token.

The problem that I am facing right now is that I added a switch to my settings screen that needs to be set to true after the token is received. But from within the NotificationCenter class I cannot access ScreenSettings.switchNotificationsEnabled control directly.

So I was trying to find a way to detect which screen is currently active but it turns out that app.CurrentLayout.Content is the main screen while the settings screen is loaded wit the Show() function and now on top of the screen stack.

I am unable to find a way to get a reference to the currently opened screen in the screen stack?

So I’m stuck. How can I set my switch to true after receiving the token in the NotificationCenter class?

One common way to solve this is to use the Notifier pattern. You have your view listen for notifications and the calling code creates a notification to be received with the relevant data once the registration is complete. Many people use the Notification_Center module of iOSKit for this: iOSKit/Modules/Notification_Center at master · kingj5/iOSKit · GitHub

1 Like

Another way:

Create a global variable of type MobileScreen, say theScreen.

When your screen Opens or Activates, do theScreen = Self

Create a method in your screen to set the switch, say FlipSwitch

Then you just call theScreen.FlipSwitch

1 Like

This is exactly how I just solved right before you posted it :slight_smile:
Thank you very much still for the advice!

1 Like

Great minds think alike and this is exactly how I solved this problem as well. I just internally track which screen is in use and use the open and activate events to keep things updated.