Use of notification hubs
Page three of the first;
An object that produces a notification hub (a singleton class for the system)
Registering an observer in the Notification Center
Methods called after receiving a notification
DEALLOC remove the Observer's identity
A second page
Send notification hubs
Create a dictionary
Return the data you want
function of Direct jump
The function of jumping directly into; call [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://110"]; texting [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@ "sms://1010"]; mail [[uiapplication sharedapplication] Openurl:[nsurl urlwithstring:@ "Mail://[email protected]"]; Open Web page [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@ "http://www.baidu.com"];
Notification Center
First page
- (void) viewdidload{ [super viewdidload]; // do any additional setup after loading the view. self.view.backgroundcolor = [uicolor redcolor]; self.title = @ "First page"; //notification hub uses //to generate a notification hub object (a singleton class for the system) NSNotificationCenter *center = [NSNotificationCenter defaultCenter];       //register an observer in the Notification Center //parameter 1: Observer // Parameter 2: What to do after the viewer receives the notification //parameter 3: Observe what things (a string tag) //parameter 4: limit the object of notification [center addobserver:self selector: @selector (Suibian:) name:@ "I'm so sleepy, I want to sleep ____99" object:nil]; uibutton *button = [[uibutton alloc] initwithframe:cgrectmake (100, 100, 100, 30)]; [button settitle:@ "button" forState:UIControlStateNormal]; button.backgroundcolor = [uicolor blackcolor]; [ Self.view addsubview:button]; [button addtarget:self action: @selector ( ButtonClick:) forcontrolevents:uicontroleventtouchupinside]; [button release] }//method called after receiving notification- (void) Suibian: (nsnotification *) Noti { self.view.backgroundcolor = noti.object; //receive changes to the color of the collection nslog (@ "object:%@", Noti.object), nslog (@ "userinfo%@", Noti.userInfo); nslog (@ "receive notification"); }- (void) dealloc{ // An object that is registered as an observer needs to be deallo by the systemBefore C, cancel your own observer identity [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc];}
second page
- (void) ButtonClick: (uibutton *) Button{// firstviewcontroller *first = [[firstviewcontroller alloc] init]; // Notification hubs use //to send notifications nsnotificationcenter *center = [nsnotificationcenter defaultcenter]; //parameter 1: Send notification to that time //parameter 2: Send notification can take one parameter //parameter 3: If you want to pass more than one parameter, just spell a dictionary, fill in the third parameter nsdictionary *dic = [nsdictionary dictionarywithobjectsandkeys:@ "Valur", @ "Key", nil]; uicolor *color = [uicolor darkgraycolor]; / /The color to return [center postnotificationname:@ "I'm so sleepy, I want to sleep ____99" object:/*@ "with parameters, paralysis, Trapped dead, "*/color userinfo:dic]; [. Self.navigationcontroller popTorootviewcontrolleranimated:yes];}
This article is from "Xiao Liu _blog" blog, please be sure to keep this source http://liuyafang.blog.51cto.com/8837978/1557029
Notification Center only with nsnotificationcenter value and call, send SMS, mail, open Web page directly open function