Tweak and App interaction program "process communication"

Source: Internet
Author: User

Core Foundation DEMO:
Tweak end:
  1. Cfnotificationcenteraddobserver (Cfnotificationcentergetdarwinnotifycenter (),
  2. Null
  3. &notificationreceivedcallback,
  4. Cfstr ("Com.chinapyg.fakecarrier-change"),
  5. Null
  6. CFNOTIFICATIONSUSPENSIONBEHAVIORCOALESCE);
  7. Callback:
  8. static void Notificationreceivedcallback (Cfnotificationcenterref center,
  9. void *observer, cfstringref name,
  10. const void *object, Cfdictionaryref
  11. UserInfo)
  12. {
  13. //.... 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
  14. }
Copy Code

App side:
1. One line of code can
    1. Notify_post ("Com.chinapyg.fakecarrier-change");
Copy Code

2. The complex point
    1. Cfstringref Observedobject =
    2. Cfstr ("Com.chinapyg.fakecarrier-change");
    3. Cfnotificationcenterref Center =
    4. Cfnotificationcentergetdistributedcenter ();
    5. Cfnotificationcenterpostnotification (center, NULL,
    6. Observedobject, NULL/* No dictionary */, TRUE);
Copy Code

///////////////////////////////////////////////////////////////////////////////////////////
Gorgeous Split-line
///////////////////////////////////////////////////////////////////////////////////////////

Cocoa DEMO:

Receive side (background):
    1. NSString *observedobject = @ "Com.chinapyg.notification";
    2. Handle notifications between different processes on a single computer
    3. Nsdistributednotificationcenter *center =
    4. [Nsdistributednotificationcenter Defaultcenter];
    5. [Center Addobserver:self
    6. Selector: @selector (callbackwithnotification:)
    7. Name: @ "Piaoyun Notification"
    8. Object:observedobject];
    9. Callback:
    10. -(void) Callbackwithnotification: (nsnotification *) mynotification;
    11. {
    12. NSLog (@ "Notification Received");
    13. }
Copy Code

Send side (APP):
    1. NSString *observedobject = @ "Com.mycompany.notification";
    2. Nsdistributednotificationcenter *center =
    3. [Nsdistributednotificationcenter Defaultcenter];
    4. [Center Postnotificationname: @ "Piaoyun Notification"
    5. Object:observedobject
    6. Userinfo:nil */No Dictionary */
    7. Deliverimmediately:yes];
Copy Code


iOS Upper interface:
    1. Handling notifications between single processes
    2. [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (callBack) Name: @ "Back" object:nil];
    3. Callback
    4. -(void) CallBack
    5. {
    6. NSLog (@ "Notification Received");
    7. }
    8. Send a notification
    9. [[Nsnotificationcenter Defaultcenter] postnotificationname:@ "back" object:self];
Copy Code

Tweak and App interaction program "process communication"

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.