iOS【 ASO项目案例】之 Inter process Communication By Rrocketbootstrap

2021-03-24 16:04:05 浏览数 (1)

点击上方蓝字关注我们

引言

原文:https://kunnan.blog.csdn.net/article/details/114694914

应用场景:进程的通信

发现vpn状态异常, 尝试关闭pppd修正

代码语言:javascript复制
#define DPost(cmd,...) [Message postMsg:@[cmd,##__VA_ARGS__] toCenter:DaemonServerKey error:nil]

                DPost(@"kill", @"pppd");

I 、基于Rrocketbootstrap的封装Message工具类进行进程间的消息通信

  • Message.h
代码语言:javascript复制
#import <Foundation/Foundation.h>

CF_ENUM(NSInteger) {
    kMsgInvalidPort = 1,
    kMsgIsNotJsonOjb = 2,
    kMsgIsSendFail = 3
};

#define MsgErrDomain @"CFMessageDomain"

@interface Message : NSObject

 (BOOL) registerMsgCenter:(NSString*) center scheduleInRunLoop:(NSRunLoop*) runloop withCallBack:(CFMessagePortCallBack) handler;
 (id) sendMsg:(id) msg toCenter:(NSString*) center error:(NSError**) error;
 (BOOL) postMsg:(id) msg toCenter:(NSString*) center error:(NSError**) error;
 (id) getJson:(CFDataRef) data;

@end

  • Message.m

0 人点赞