There is also a type of event generation function in iOS, that is, notification. Through notifications, You can trigger the RESPONSE event under certain conditions. Similar to the Broadcast Mechanism in Android, after receiving a notification (broadcast), you can execute the specified method.
Obtain the notification object through nsicationicationcenter and register and use the notification.
The following uses an example:
Uiapplication * Application = [uiapplication sharedapplication];
[[Nsicationcenter center defacenter center] addobserver: selfselector: @ selector (applicationwillresignactive :) name: uiapplicationwillresignactivenotification object: Application];
The above code registers a notification. addobserver is the object that receives the notification, usually self, and Selector is the operation to be executed after the notification is received. It can be understood as an operation event, name is the name of the notification. Here, uiapplicationwillresignactivenotification is used, which means that before the application enters the background, the object only receives notifications from which objects, usually set to nil.
-(Void) applicationwillresignactive :( nsnotification *) Notification
{
}
You can implement the response operation in the above method.
This process is to trigger the notification before the application enters the background (press the Home Key), and then execute applicationwillresignactive: notification method to complete some operations.
To join our QQ group or public account, see: Ryan's
Zone public account and QQ Group
Welcome to my Sina Weibo chat: @ Tang Ren _ Ryan