IOS Study Notes 11-ios notification center

Source: Internet
Author: User
Tags notification center

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.