1 在后台进程中创建一个用于进程通讯的 CFMessagePortRef #define APP_ID "yohunl.support.mach.port" #define MACH_PORT_NAME APP_ID -(void)init { CFMessagePortRef local = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR(MACH_PORT_NAME), mouseCallBack, NULL, NULL); CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, local, 0); CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes); } //其中的mouseCallback是回调函数,其声明是 CFDataRef mouseCallBack( CFMessagePortRef local, SInt32 msgid, CFDataRef cfData, void *info) ; 在前台进程中使用发送消息的模式 -(void).... { //..... CFMessagePortRef bRemote = CFMessagePortCreateRemote(kCFAllocatorDefault, CFSTR(MACH_PORT_NAME)); // tell thread b to print his name char message[255]="lingdaiping,yohunl"; CFDataRef data; data = CFDataCreate(NULL, (UInt8 *)message, strlen(message)+1); (void)CFMessagePortSendRequest(bRemote, CFSTR(MACH_PORT_NAME), data, 0.0, 0.0, NULL, NULL); CFRelease(data); CFRelease(bRemote); //.... }