How to send a notification to all ViewControllers?

I am developping an ios application and I need to check, from time to time (every 10 minutes), if the license for the user is still valid.

So, I wish to know how can i have a central monitoring code, wich is activated from a timer, and some sort of communication to any view wich is used at that moment (player, configuration, tableview, etc...).

I was told that this could be done by using singleton, but I don't know if this is the best way since it must use timer to check the license from server every 10 minutes.

Can anybody give me some clue, maybe some example code?


Thank very much to all for any help.

Replies

I would do this via the

Notification
and
NotificationCenter
APIs. The central monitoring code can define a notification and post that notification when a relevant event occurs. Each of the view controllers can subscribe to that notification and act appropriate when it’s received.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"