IOS learning: nsnotification

Source: Internet
Author: User

Http://blog.csdn.net/kaizi318/article/details/8294127

Each process has a default nsicationicationcenter. You can use the defacenter center class method to obtain the instances of this message center. The message center can process messages between different objects in the same process. If you want to communicate between processes on the same machine, you need to use nsdistributednotificationcenter.

The message center distributes messages synchronously to all the observers. In other words, the control is returned to the caller after all the observers receive the messages and process the messages.

 

1 // Step 1: Implement callback function 2-(void) callback 3 {4 nslog (@ "Callback method called"); 5} 6 7 // Step 2: registering a notification with the notification center indicates the notifications that self is interested in, when the notification center receives this notification, it will notify the current object. // is the name used as the unique identifier for the notification? 9 [[nsicationicationcenter defacenter center] addobserver: self10 selector: @ selector (callback) 11 name: @ "God-level notification" 12 object: Nil]; 13 14 // remember to cancel registration when appropriate
15 [[nsicationicationcenter defacenter center] removeobserver: Self name: @ "God-level notification" Object: Nil]; 16 17 // Step 3: send a notification to the notification center anywhere in the same thread. Nsnotification is the 18 [[nsnotificationcenter defacenter center] postnotificationname: @ "God-level notification" Object: Nil] of synchronous blocking.

 

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.