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