[文档][电脑版][技术中心][电脑部]我聊(Mac)

2017-12-11  本文已影响30人  绍清_shao

我聊模块两个核心类

MJMessagesBubbleController类

MJMessagesBubbleController

MJStatusBarController类

MJStatusBarController

点击我聊图标,启动我聊过程详细步骤:

mj_modules::ShowMsgBubble("", true) {
  1. 判断是否登录和是否存在组织
  2. 是否启动应用ID为kDockClientMsgBoxIdentifierKey的应用
  (1).如果没启动则启动
  (2).如果有启动则获取MJStatusBarController全局单例,
  并调用showBubbleWithURL:base::SysUTF8ToNSString(str_url) openlast:is_open_last_new fromType:fromType]显示
}

- (void)showBubbleWithURL:(NSString*) str_url openlast:(bool)is_open_last_new fromType:(mj_modules::ShowMsgFromType)fromType {
  1. 判断是否从热键中启动
  2.[self showWindowWithTitle:str_title_ url:str_url profile:[self getProfile]] 显示
}

- (void)showWindowWithTitle:(NSString *)str_title url:(NSString *)str_url profile:(Profile *) profile{
  1. MJMessagesBubbleController 调用实例方法 showMessageBubble
}

- (void)showMessageBubble {
// 显示
}

Dock栏图标与115浏览器之间的通讯

当点击我聊图标时

Dock栏我聊是个独立APP,作为消息的发送者,需要构建发送信息的数据:

// 生成Remote port
CFMessagePortRef remotePort;
remotePort = CFMessagePortCreateRemote(nil, (CFStringRef)kDistributedObjectServerForDockMsgBoxNameKey)

// 构建发送数据(string)
NSData *data = [NSJSONSerialization dataWithJSONObject:dicSend options:nil error:nil];
CFDataRef dataPtr = CFDataCreate(kCFAllocatorDefault,data.bytes, data.length);

// 执行发送操作
SInt32 status = CFMessagePortSendRequest(remotePort, messageID, dataPtr, timeout, timeout, NULL, NULL);
​

代码说明:

115浏览器作为消息接收者,需要注册消息监听:

NSString *kDistributedObjectServerForDockMsgBoxNameKey = @"115Browser.MsgBox.Dock.Chanel";

if (localPort) {
                CFRelease(localPort);
            }
            if (runLoopSource) {
                CFRelease(runLoopSource);
            }
            localPort =  CFMessagePortCreateLocal(nil, (CFStringRef)kDistributedObjectServerForDockMsgBoxNameKey, CallbackMsgFromClient, nil,nil);
            runLoopSource = CFMessagePortCreateRunLoopSource(nil, localPort, 0);
            CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
             NSLog(@"start listenning");

代码说明:

在回调方法CallbackMsgFromClient内接受来自Dock栏我聊发送的信息。

static CFDataRef CallbackMsgFromClient(CFMessagePortRef port, SInt32 messageID, CFDataRef data, void *info)
{
NSLog(@"onRecvMessageCallBack is called");
.....
}

回调函数各个参数的含义为:

上一篇 下一篇

猜你喜欢

热点阅读