IOS notification mechanism

Source: Internet
Author: User

On the internet, it is often said that the iOS notification mechanism uses the observer pattern, which has two characters, one is poster (sender) and the other is observer (Subscriber receiving information). But I think the important role is the notification center, which is the core of the whole notification mechanism, the message sent by the poster sender must reach the notification center, and then by the notification center according to the message by which the observer subscribers, the message to those subscribers to distribute. The whole can be analogous to the current e-mail structure. But for extra explanation, iOS notifications, although also called notification notifications, are not the same as notifications in Android, and notifications in Android are a form of message push, and there's definitely a message push in iOS, which is the content of the push mechanism section. said that this notification mechanism is the original in the learning of C # event, but the event here is for the whole system of global events, any party to the system of this global event to register the binding method, to the event is triggered when it can be executed.

The entire notification of the operation process, we just need to set the poster and observer to be OK

For the Poster operation is relatively simple, he only need to go to the notification center to push the notification, using the following code

Object  is Posterone "];

Or

Object  is Posterone "]);

Notificationwithname:object: The method also has an overload of UserInfo: parameter, which is the dictionary type of nsdictionary, which is used to pass user parameters.

For Observer is relatively not poster so simple, in C # in the event registration binding, also found that the trigger event is just like the call method as a child call, but the registration of the party needs to bind the method of the event, and define methods, In the IOS notification mechanism, you need to register, callback processing (that is, the method definition in the event), run out and delete.

Registered
object: nil];

The parameters here are the same as postnotificationname:object: corresponding. Register the notification name parameter to fill in the corresponding value

Callback Processing
-(void) CallBack1 (nsnotification*) notification{    notification.name:// name of the notification     notification.  Object; // Object when sending a notification    Notification.userinfo// UserInfo} When sending a notification
Delete

A delete operation is required after the message is finished (that is, the message received is no longer processed)

[[Nsnotificationcenter defaultcenter]removeobserver:self]; // Delete all registered notifications object: nil]; // Delete the notification named "Postone". 

iOS notification mechanism

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.