iOS越狱机子 进程间通讯

本文介绍了使用CFMessagePort进行进程间通信的实现方法,包括发送请求及接收响应的过程,并提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// 下面是进程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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值