Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent android.content.BroadcastReceiver in Swift

I would like to know if there is an equivalent android.content.BroadcastReceiver in Swift. I would need the same handler like onReceive(Context context, Intent intent)

It is possible ?

Thank you

Ysee

like image 844
YMonnier Avatar asked May 22 '15 12:05

YMonnier


People also ask

What is a BroadcastReceiver in Android?

Android BroadcastReceiver is a dormant component of android that listens to system-wide broadcast events or intents. When any of these events occur it brings the application into action by either creating a status bar notification or performing a task.

What file is used to register the BroadcastReceiver?

You register this broadcast receiver either in the manifest file or in the code. These events are intents. So, whenever these kinds of events happen, an intent is triggered.

Is broadcast receiver deprecated in Android?

What does saving battery have to do with BroadcastReceivers? With Android Nougat, the support for registering three different implicit BroadcastReceivers in your AndroidManifest was removed. With apps targeting Android O, all implicit BroadcastReceivers registered in the manifest (except these) will stop working.

What is the life cycle of BroadcastReceiver?

A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent) . Once your code returns from this function, the system considers the object to be finished and no longer active.


1 Answers

In Swift in order to achieve the same effect you would use the NSNotificationCenter. Take a look at this link below for some guidance

http://www.andrewcbancroft.com/2014/10/08/fundamentals-of-nsnotificationcenter-in-swift/

like image 67
Chackle Avatar answered Oct 23 '22 15:10

Chackle