Notification Center only with nsnotificationcenter value and call, send SMS, mail, open Web page directly open function

Source: Internet
Author: User
Tags notification center

Use of notification hubs

Page three of the first;

    1. An object that produces a notification hub (a singleton class for the system)

    2. Registering an observer in the Notification Center

    3. Methods called after receiving a notification

    4. DEALLOC remove the Observer's identity

A second page

    1. Send notification hubs

    2. Create a dictionary

    3. 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

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.