IOS Notification Center Nsnotificationcenter detailed

Source: Internet
Author: User

Nsnotificationcenter the application of the scene, the principle of mechanism, the use of steps.

Order of use of notification hubs: first make sure that the Observer is registered, because sending notifications is instantaneous, and if there are no registered observers, then registration is not received until the notification is sent.

Summary: Notifications are only sent to the currently listening object.

Code

Registration Notifications Register for monitoring on the page that cares about the notification

[[nsnotificationcenter defaultcenter] addobserver:self selector:@ Selector(Tongzhi:) name:@ "Tongzhi" object:nil];

Send notifications Make sure you have registered to listen to the notification.

Nsdictionary *dict =@{@ "key":@ "Value"};

// Create a notification

nsnotification *notification =[nsnotification notificationwithname:@ "Tongzhi" Object:nil userInfo:d ICT];

// send notifications via notification hubs

[[nsnotificationcenter defaultcenter] postnotification: notification];

Method of callback after receiving notification

-(void) Tongzhi: (nsnotification *) text{

NSLog(@ "%@", text. UserInfo[@ "key"]);

NSLog(@ "--receive notification ------");   

}

Be sure to remove the listener when you don't need to receive notifications

[[Nsnotificationcenter Defaultcenter] removeobserver:self];

Http://www.wtoutiao.com/a/1385824.html This is a good summary.

Pending summary ...

IOS Notification Center Nsnotificationcenter detailed

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.