Go: iOS Notification Center

Source: Internet
Author: User

Go:IOS Notification Notification Center

: nsnotification
1. Notification Hubs overview
Notification hubs are essentially a mechanism for providing message broadcasts within a program. Notification hubs cannot communicate between processes. is actually a setter that forwards the message to the desired object, based on the internal message forwarding. Notification hubs is based on the observer pattern, which allows you to register and delete observers.
A nsnotificationcenter can have a lot of notification messages nsnotification, for each nsnotification can have a lot of observers observer to receive notifications.
2. Notification hubs two important classes
Nsnotificationcenter: This is the soul of the notification hub in iOS, which implements the observer pattern and provides the developer with an interface such as registering and deleting the observer, and we can use a singleton to get an example of it (note, There is only one Nsnotificationcenter instance object inside a program).
Nsnotification: This is the carrier of the message, through which the message content can be passed to the observer. Where: Name corresponds to the message name designation. object is usually the sender itself, dictionary is the message content that is passed.
3. How notification hubs are used
Through, we can see that the use of notification hubs can be divided into 4 steps.
What you need to mention here is that sending a message can be more than just a user-initiated or a system-initiated.
When we register the observer for a message, if we have the corresponding message, the observer receives the corresponding message and expands the processing. It is important to note that when you finish using the message, you do not want to receive the message, you need to remove the observer, otherwise an error will occur.

Registration Notice: Where to accept the message
[[Nsnotificationcenter defaultcenter]  addobserver:self selector: @selector (mytest:) name:@ "PostData" object:nil];
Parameter Description:
Addobserver: The Observer, where the notification is received;
Selector: What method is called after receiving the notification, that is, the callback function;
Name: The name of the notification, which is also the only indication of the notification, which the compiler will use to find the notification.
Send notification: Invokes the method at the Observer.
[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "PostData" Object:searchfriendarray];
 

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.