iOS notification using the book case is easy to understand

Source: Internet
Author: User


/* The notification name */
Const NSString *resultofappendingtwostringsnotification =
@ "Resultofappendingtwostringsnotification"; /* Keys inside the dictionary, our notification sends */
Const NSString
*resultofappendingtwostringsfirststringinfokey = @ "firststring";
Const NSString
*resultofappendingtwostringssecondstringinfokey = @ "secondstring";
Const NSString
*resultofappendingtwostringsresultstringinfokey = @ "resultstring";

Send Notification method
-(void) broadcastnotification{

NSString *firstname = @ "Anthony";
NSString *lastname = @ "Robbins";
NSString *fullname = [FirstName stringbyappendingstring:lastname];

Nsarray *objects = [[Nsarray alloc] Initwithobjects:
FirstName,
LastName,
FullName,
NIL];
Nsarray *keys = [[Nsarray alloc] Initwithobjects:resultofappendingtwostringsfirststringinfokey, Resultofappendingtwostringssecondstringinfokey, Resultofappendingtwostringsresultstringinfokey,
NIL];
Nsdictionary *userinfo = [[Nsdictionary alloc] initwithobjects:objects Forkeys:keys];
Nsnotification *notificationobject =
[Nsnotification notificationwithname: (NSString *) Resultofappendingtwostringsnotification object:self
Userinfo:userinfo];
[[Nsnotificationcenter Defaultcenter] postnotification:notificationobject];

}

Listener Notification Invocation Method
-(void) appendingisfinished: (nsnotification *) paramnotification
{

NSLog (@ "Notification is received.");
NSLog (@ "Notification object =%@", [Paramnotification object]);
NSLog (@ "Notification user-info Dict =%@", [paramnotification UserInfo]);
}


-(void) viewdidload
{
Monitoring notifications
[[Nsnotificationcenter Defaultcenter]
Addobserver:self
Selector: @selector (appendingisfinished:)
Name: (NSString *) resultofappendingtwostringsnotification object:self];


Send Notifications
[Self broadcastnotification];

}

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.