7.iOS Notification

Source: Internet
Author: User

1. Notification Center Awareness

Notification hubs are essentially a mechanism for providing message broadcasts within a program. Notification hubs cannot communicate between processes, it can only communicate within the program, and cannot communicate across application processes. Notification hubs, when the notification hub receives a message, forwards the message to the Subscriber according to the settings, based on a message forwarding from within. Notification hubs is based on the observer pattern, which allows you to register and delete observers. Notification hubs, like proxy mode, can implement multiple inter-object communication, and notification hubs can send one notification to multiple listeners, while proxy mode can only add one agent per object. However, the model is a low-coupling design that implements communication between objects.

2. Use of notification hubs

First step: Register Notification Center (who is going to accept the broadcast)

Parameter 1 who's going to pick up the radio?

Parameter 2 actions to take after receiving a broadcast

Parameter 3 which broadcast to accept (also on broadcast identification)

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (runsel:) name:@ "MCJ" object:nil];

Step two: Send a broadcast this method is usually written in other objects when there are any variables like

Parameter 1 adds an identity to the broadcast (this value can be used to differentiate between broadcasts in the receiving broadcast)

Parameter 2 parameters that need to be passed can pass nil.

[Nsnotificationcenter Defaultcenter] postnotificationname:@ "MCJ" Object:array];

Step three: Implement the method to be executed after receiving the broadcast, if the parameters need to add (nsnotification *) sender

Sender.object is the parameter we passed over.

-(void) Runsel: (Nsnotification *) Sender {

    Nsarray *array =sender.object;
    _namelable.text = array[0];

_passwordlabel.text =
ARRAY[1];
    self.view.backgroundcolor= [Uicolor Redcolor];}

Fourth Step: Remove notifications (there are two ways)

-(void) Dealloc {

Remove the specified notification? Heart

    [[Nsnotificationcenterdefaultcenter]
removeobserver:selfname:@ "MCJ" object:nil];

Remove all notifications? Heart

    [[Nsnotificationcenterdefaultcenter]
Removeobserver:self];}

7.iOS Notification

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.