iOS 接入场景

临境直播观看 SDK 的接入可以通过两种场景;
一、原生场景:直接从 App 原生进入直播观看;
二、H5 嵌入场景:从嵌套在 webview 的 H5 中,进入直播观看;

原生场景

原生场景接入方式

  1. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  2. [params setValue:@"" forKey:kLivePullSDKeyRoomCode];//直播室roomCode 必传
  3. [params setValue:@"" forKey:kLivePullSDKeyUserId];//用户userId 必传
  4. [params setValue:@"" forKey:kLivePullSDKeyUserName];//用户昵称 必传
  5. [params setValue:@"" forKey:kLivePullSDKeyAvatar];//用户头像
  6. [params setValue:@"" forKey:kLivePullSDKeyPassword];//观看密码
  7. [params setValue:@"" forKey:kLivePullSDKeyLoginName];//产线用户登陆名称
  8. [params setValue:@"" forKey:kLivePullSDKeyUserPoint];//用户积分
  9. [[YXTLivePullSDK getInstance] loginChatRoomWithParam:params inNav:当前的navigationController];

H5嵌入场景

H5嵌入场景接入方式

直接在需要跳转的地方添加如下代码:

自定义 UIViewController 继承 YXTWebSDKViewController
实现协议

  1. //protocol 协议名 jsModel 协议传回数据模型
  2. - (void)appJSListeningProtocol:(NSString *_Nullable)protocol param:(YXTJSModel *_Nullable)jsModel;

拦截 protocol yxt_app_live_open 协议
获取

  1. //直播房间 id
  2. NSString *roomCode = [[NSString decodeString:jsModel.param] mj_JSONObject][@"roomcode"];
  3. //直播房间 密码
  4. NSString *password = [[NSString decodeString:jsModel.param] mj_JSONObject][@"password"];
  1. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  2. [params setValue:@"" forKey:kLivePullSDKeyRoomCode];//直播室roomCode 必传
  3. [params setValue:@"" forKey:kLivePullSDKeyUserId];//用户userId 必传
  4. [params setValue:@"" forKey:kLivePullSDKeyUserName];//用户昵称 必传
  5. [params setValue:@"" forKey:kLivePullSDKeyAvatar];//用户头像
  6. [params setValue:@"" forKey:kLivePullSDKeyPassword];//观看密码
  7. [params setValue:@"" forKey:kLivePullSDKeyLoginName];//产线用户登陆名称
  8. // 正式api地址
  9. #define DX_BaseDaxueApiUrl https://api-qida.yunxuetang.cn/v1/qdl/
  10. // 测试api地址
  11. #define DX_BaseDaxueApiUrl = "https://devinner.yunxuetang.com.cn/qidaliveapi/v1/";
  12. NSString * requestURL = [NSString stringWithFormat:@"%@live/getvalidpoints",DX_BaseDaxueApiUrl];
  13. //请求头
  14. NSMutableDictionary *requestDict = [NSMutableDictionary dictionary];
  15. [requestDict setValue:@"" forKey:@"Source"]; //@"506"
  16. [requestDict setValue:@"" forKey:@"Token"]; // tokenh5localstorage获取
  17. [[YXTNetworkingSDK getInstance] requestHTTPHeaderFields:requestDict];
  18. [[YXTNetworkingSDK getInstance] request:YXTHTTPGet url:requestURL params:nil success:^(id response) {
  19. if (response[@"validPoints"]) {
  20. [params setValue:response[@"validPoints"] forKey:kLivePullSDKeyUserPoint];
  21. }
  22. [[YXTLivePullSDK getInstance] loginChatRoomWithParam:params inNav:vc.navigationController];
  23. } failure:^(NSInteger statusCode, NSString *errorKey, NSString *errorMessage, NSError *error) {
  24. [params setValue:@"0" forKey:kLivePullSDKeyUserPoint];
  25. [[YXTLivePullSDK getInstance] loginChatRoomWithParam:params inNav:vc.navigationController];
  26. }]

关于作者

江苏云学堂网络科技有限公司开发人员,如有问题请发送邮件至 yll@yxt.com