点击上方蓝字关注我们
引言
原文:https://kunnan.blog.csdn.net/article/details/114694914
应用场景:进程的通信
代码语言:javascript复制发现vpn状态异常, 尝试关闭pppd修正
#define DPost(cmd,...) [Message postMsg:@[cmd,##__VA_ARGS__] toCenter:DaemonServerKey error:nil]
DPost(@"kill", @"pppd");
I 、基于Rrocketbootstrap的封装Message工具类进行进程间的消息通信
- Message.h
#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