IPhone DevelopmentDaemonProcessAnd front-endProcessBetweenCommunicationThis is the content to be introduced in this article. When we create an application based on mobilesubstrate, there are usually some frontend and backend programs, such as apple skins. This requires foreground procedural code information to go to the background.Process, There are two methods
One is file-based mode.
That is, set a timer in the background program to regularly read the file of user interaction information. This communication mechanism also solves the problem. However, the defect is that you need to run a timer all the time to check whether the front-end has passed the information.
Another method is to use CFMessagePortRef.
The typical mode is as follows:
- #define APP_ID "yohunl.support.mach.port"
- #define MACH_PORT_NAME APP_ID
Create a CFMessagePortRef for Process Communication in the background process
- CFMessagePortRef local = CFMessagePortCreateLocal(kCFAllocatorDefault,
- CFSTR(MACH_PORT_NAME), mouseCallBack, NULL, NULL);
- CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, local, 0);
- CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
The mouseCallback is the callback function, and its declaration is
- CFDataRef mouseCallBack(CFMessagePortRef local, SInt32 msgid, CFDataRef cfData, void *info);
At the front-endProcessUse the message sending mode in
- 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);
There is also a semaphore mechanism that I have not studied yet, but I have seen other programs used, and it should be OK!
Summary:IPhone DevelopmentDaemonProcessAnd front-endProcessBetweenCommunicationI hope this article will be helpful to you!