6.6 生命周期处理

在建立连接后收到 onConnect 时需要发送上线消息:

[[V5ClientAgent shareClient] shouldClientOnline];

在用户离开会话界面后,不需要使用客服对话时,发送下线消息:

[[V5ClientAgent shareClient] shouldClientOffline];

在使用SDK接口进行开发时,【必须】调用上述代码,等同于使用 SDK 提供的UI开发中5.5AppDelegate 中添加的下面代码(SDK接口进行开发则是执行上述方法):

- (void)applicationDidEnterBackground:(UIApplication *)application {
  //退出到后台时,通知 SDK 用户离线
  [[V5ClientAgent shareClient] onApplicationDidEnterBackground];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
  //移动到前台时,通知 SDK 用户上线并连接
  [[V5ClientAgent shareClient] onApplicationWillEnterForeground];
}

此外,不使用客服功能时建议关闭会话连接以节省资源,建议在开启会话界面的前一个界面的 viewDidAppear:方法中调用关闭客服的方法:

- (void)viewDidAppear:(BOOL)animated { // 前一 viewController 中
  // 不使用客服功能时(在会话 VC 退出后,即本 VC 显示时)退出消息客户端
  if ([V5ClientAgent shareClient].isConnected) {
    [[V5ClientAgent shareClient] stopClient];
  }
}

results matching ""

    No results matching ""

    results matching ""

      No results matching ""