iOS越狱机子 进程间通讯

来源:互联网 发布:淘宝参数是什么意思 编辑:程序博客网 时间:2024/06/06 00:22

// 下面是进程A发送请求,返回
CFDataRef returnData = NULL;            CFMessagePortRef remote = CFMessagePortCreateRemote(kCFAllocatorDefault, (CFStringRef)STATIC_COFIG_MESSAGE_PORT);            NSLog(@"\n\n mobile phone 2");            int iResult = CFMessagePortSendRequest(remote, 0, NULL, 5.0, 5.0, kCFRunLoopDefaultMode, &returnData);            NSLog(@"\n\nCFMessagePortSendRequest Result: %d", iResult);                        CFPropertyListFormat format;            CFPropertyListRef dicRef = CFPropertyListCreateWithData(NULL, returnData, kCFPropertyListImmutable, &format, NULL);                                    m_Config = [[NSDictionary alloc] initWithDictionary:(NSDictionary *)dicRef];


// 下面是进程B接收代码

CFMessagePortRef local2 = CFMessagePortCreateLocal(NULL,                                                              (CFStringRef)STATIC_COFIG_MESSAGE_PORT,                                                              returnConfigDic, NULL, NULL);            CFRunLoopSourceRef source2 = CFMessagePortCreateRunLoopSource(NULL, local2, 0);            CFRunLoopAddSource(CFRunLoopGetCurrent(), source2, kCFRunLoopDefaultMode);



// 回调

CFDataRef returnConfigDic(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info){    NSLog(@"\n\n returnConfigDic 1");    if (m_Config != nil) {        NSLog(@"\n\n returnConfigDic 2");        NSLog(@"\n\n returnConfigDic m_Config: %@", m_Config);        CFDataRef configDataRef = CFPropertyListCreateData(NULL, (CFPropertyListRef)m_Config, kCFPropertyListXMLFormat_v1_0, kCFPropertyListImmutable, NULL);        return configDataRef;    } else {        NSDictionary *nilDic = [[NSDictionary alloc] initWithObjects:@[@"0"] forKeys:@[STATIC_MESSAGE_TELEPHONE_NUMBER]];        CFDataRef nilConfigDataRef = CFPropertyListCreateData(NULL, (CFPropertyListRef)nilDic, kCFPropertyListXMLFormat_v1_0, kCFPropertyListImmutable, NULL);        return nilConfigDataRef;    }}


可能存在些内存泄露问题~~ 初学者,见谅 & 欢迎提宝贵意见


参考Link:

http://hi.baidu.com/ataraxia2012/item/29d320d1a7c9eb42d63aae80

0 0
原创粉丝点击