IPhone Message notification-nsnotification and nsnotifcenter Center

Source: Internet
Author: User

1. nsnotification: message or notification

Three member variables

-(Nsstring*) Name;

-(ID) Object;

-(Nsdictionary*) Userinfo;

Notification name: Name,

Message sender: object. The proxy can receive the nsnotification method.Callback to object

Additional information: userinfo

 

2. nsicationicationcenter: Message Center

In Singleton mode, you must use the following methods to access

 
[Nsnotificationcenter defacenter center]

3. broadcast a notification

 
[[Nsicationcenter center defacenter center] postnotificationname:@"Aevent" Object: Nil];

Send a notification with the accompanying information

[[Nsicationcenter center defacenter center] postnotificationname:@"Event" Object: Nil userinfo :( nsdictionary *) auserinfo];
 
Auserinfo is a dictionary

Send a notification directly

 
[[Nsicationcenter center defacenter center] postnotification :( nsnotification *) Notification];

4. Register a notification listener

 
[[Nsicationcenter center defacenter center] addobserver: Self selector: @ selector (onhandler :) name:@"Aevent" Object: Nil];

When registering a notification, you can specify a specific broadcaster object, but it is not required.

5. Remove a listener

[[Nsicationcenter center defacenter center] removeobserver: Self Name:@"Aevent" Object: Nil];

6. Notify the method to be called

 
-(Void) Onhandler :( nsnotification *) notif
{
Nsdictionary * user_info = [notif userinfo];
//Execute custom Logic
}

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.