Core Foundation DEMO:
Tweak end:
- Cfnotificationcenteraddobserver (Cfnotificationcentergetdarwinnotifycenter (),
- Null
- ¬ificationreceivedcallback,
- Cfstr ("Com.chinapyg.fakecarrier-change"),
- Null
- CFNOTIFICATIONSUSPENSIONBEHAVIORCOALESCE);
- Callback:
- static void Notificationreceivedcallback (Cfnotificationcenterref center,
- void *observer, cfstringref name,
- const void *object, Cfdictionaryref
- UserInfo)
- {
- //.... According to the name to determine what kind of message, the following client passed null, so there is no need to judge, in a variety of messages need to use
- }
Copy Code
App side:
1. One line of code can
- Notify_post ("Com.chinapyg.fakecarrier-change");
Copy Code
2. The complex point
- Cfstringref Observedobject =
- Cfstr ("Com.chinapyg.fakecarrier-change");
- Cfnotificationcenterref Center =
- Cfnotificationcentergetdistributedcenter ();
- Cfnotificationcenterpostnotification (center, NULL,
- Observedobject, NULL/* No dictionary */, TRUE);
Copy Code
///////////////////////////////////////////////////////////////////////////////////////////
Gorgeous Split-line
/////////////////////////////////////////////////////////////////////////////////////////// Cocoa DEMO:
Receive side (background):
- NSString *observedobject = @ "Com.chinapyg.notification";
- Handle notifications between different processes on a single computer
- Nsdistributednotificationcenter *center =
- [Nsdistributednotificationcenter Defaultcenter];
- [Center Addobserver:self
- Selector: @selector (callbackwithnotification:)
- Name: @ "Piaoyun Notification"
- Object:observedobject];
- Callback:
- -(void) Callbackwithnotification: (nsnotification *) mynotification;
- {
- NSLog (@ "Notification Received");
- }
Copy Code
Send side (APP):
- NSString *observedobject = @ "Com.mycompany.notification";
- Nsdistributednotificationcenter *center =
- [Nsdistributednotificationcenter Defaultcenter];
- [Center Postnotificationname: @ "Piaoyun Notification"
- Object:observedobject
- Userinfo:nil */No Dictionary */
- Deliverimmediately:yes];
Copy Code
iOS Upper interface:
- Handling notifications between single processes
- [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (callBack) Name: @ "Back" object:nil];
- Callback
- -(void) CallBack
- {
- NSLog (@ "Notification Received");
- }
- Send a notification
- [[Nsnotificationcenter Defaultcenter] postnotificationname:@ "back" object:self];
Copy Code |
Tweak and App interaction program "process communication"