跳转至
400-881-9892

文档中心

官方文档,可查阅产品介绍、快速入门、用户指南、开发指南、API参考、SDK参考、帮助等信息。

文档中心 互动课堂

iOS 集成方法

1. 前言

在您阅读此文档时,我们假定您已经具备了基础的 iOS 应用开发经验,并能够理解相关基础概念。

1.1 、环境准备

请到拓课官方网站下载 Talkcloud SDK iOS 版。 如果您打算使用拓课公网服务器,使用 DEMO 里填写的默认参数即可进入教室;

1.2 、版本兼容

兼容 iOS 12及以上版本

2. 工程设置

2.1 、导入 Framework
  • TKUISDK.framework 提供了所有的教室功能;
  • TKWhiteBoard.framework 提供了所有的白板功能;
  • TKRoomSDK.framework 提供音视频流的传输、信令的传递以及重要功能逻辑的实现。
  • TKExtension.framework 业务支持类。
  • TKScreenShareService.framework 提供iOS设备屏幕共享。(根据需求非必选)。
2.2 、添SDK 到 TARGETS
  • Framework,Lbraries,and Embedded Content 下的 Embed 属性都设置为 Embed&Sign。
  • TKWhiteBoard.framework、TKRoomSDK.framework、TKExtension.framework、TKScreenShareService.framework 已在 TKUISDK.framework 中调用,除非有特定需求,否则无需额外调用。
2.3 、info.plist 文件的设置

添加权限申请及相应文本

1
2
3
4
5
Privacy - Camera Usage Description
Privacy - Microphone Usage Description
Privacy - Photo Library Additions Usage Description
Privacy - Photo Library Usage Description
Privacy - Location When In Use Usage Description
2.4 、添加第三方库
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
必要(V4.17.4.0及之后) 
#腾讯播放器 //需注册腾讯播放器licence,否则无法使用
pod 'TXLiteAVSDK_Player'

非必要
#如果使用分享功能可添加以下三方库,具体根据需求确定
pod 'UMCommon', '7.2.5'
pod 'UMShare/UI', '6.10.1'
# 微信完整版
pod 'UMShare/Social/WeChat', '6.10.1'
# 集成QQ/QZone/TIM(完整版7.6M)
pod 'UMShare/Social/QQ', '6.10.1'
# 集成新浪微博(完整版25.3M)
pod 'UMShare/Social/Sina', '6.10.1'
2.5 、http 请求
1
App Transport Security Settings Allow Arbitrary Loads YES
2.6 、uild Settings 设置项
1
2
3
Enable Bitcode : NO
User-Defined : arm64
OTHER_LDFLAGS : 加入 -ObjC
2.7 、外部链接打开

app 的 url schemes targets -> info -> URL Types 添加 协议头 enterroomnew(添加此协议头后 在浏览器点击特定链接才可以打开 app,此协议头可和后端协商自定义,enterroomnew 为拓客云默认协议头)

3. AppDelegate.m 文件的配置

3.1 、引入头文件
1
#import <TKUISDK/TKUISDK.h>
3.2 、回调方法里加入对应的方法:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 加载自定义的loadingGIF图,key值为 企业的authkey。
    // 不调用此方法,或者key值传空,加载默认的GIF图。
    [[TKAPPSetConfig shareInstance] roomLoadingImageWithPath:@""];
    //注册腾讯播放器Licence (V4.17.4.0之后)
    [[TKTxLiveSetting shareInstance] registerTxLicenceKey:@"LicenceKEY" licenceURL:@"licenceURL"];
    详见DEMO
}

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    //添加通过链接跳转APP的方法
    [[TKEduClassManager shareInstance] joinRoomWithUrl:url.relativeString];
}

-(void)applicationWillTerminate:(UIApplication *)application {
    // 在程序被kill的时候,添加退出房间的方法
    [[TKEduClassManager shareInstance] leaveRoom];
}

-(void)applicationDidBecomeActive:(UIApplication *)application {
    // 添加用于恢复数据的方法
    [[TKEduClassManager shareInstance] applicationDidBecomeActive];
}

4. TKUISDK.framework

  • TKAPPSetConfig 类主要提供了进入教室前的配置信息的接口。
  • TKEduRoomDelegate 类提供了进入教室的一些回调,可根据自己的需求使用。
  • TKEduClassManager 类提供进房间及回放相关接口。
TKEduClassManager

a.进入房间的方法:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/// 进入房间的函数
/// @param paramDic NSDictionary类型键值需要传递
/// serialNSString * 课堂号)、
/// userrole(NSNumber * 学生 2,老师 0,旁听生 6, 巡课 4)
/// nicknameNSString * 用户昵称)、
/// userid(NSString * 用户ID选填)
/// password(NSString * 密码 有则传)
/// norecord(是否不录制当前用户视频 0,录制 1,不录制),
/// 桌面共享:bundleid (桌面共享进程的bundleid,为空视为无共享功能) groupid (桌面共享的appGroupid)
/// @param controller 当前页面的控制器通常与下边delegate相同
/// @param delegate 遵循TKEduEnterClassRoomDelegate代理供给用户进行处理
/// @param isFromWeb 是否是从网址链接进入进入
/// @return 是否成功 0 成功 其他失败

- (int)joinRoomWithParamDic:(NSDictionary*)paramDic ViewController:(UIViewController*)controller Delegate:(id<TKEduRoomDelegate>)delegate isFromWeb:(BOOL)isFromWeb;

b.进入常规回放:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
/// 进入常规回放房间的函数
/// @param paramDic NSDictionary类型 键值需要传递
/// serialNSString * 课堂号)、
/// recordtitle(NSString * 根据后台返回的回放标题)
/// userid(NSString * 用户ID选填 传入后只播放除老师外该id的音视频)
/// @param controller 当前页面的控制器通常与下边delegate相同
/// @param delegate 遵循TKEduEnterClassRoomDelegate代理供给用户进行处理
/// @param isFromWeb 是否是从网址链接进入进入
/// @return 是否成功 0 成功 其他失败

- (int)joinPlaybackRoomWithParamDic:(NSDictionary *)paramDic ViewController:(UIViewController*)controller Delegate:(id<TKEduRoomDelegate>)delegate isFromWeb:(BOOL)isFromWeb;

c.通过链接进入教室\直播\回放:

1
2
3
4
5
 /**
 从网页链接进入房间(直播\回放)
 @param url 网页url userid (&拼接userid 只播放老师和该userid学生)
 */
- (void)joinRoomWithUrl:(NSString*)url;

d.进入 mp4 回放 :

1
2
3
4
/// 播放MP4回放
/// @param vc 控制器用于弹出播放页面
/// @param path 视频路径
-(void)playVideo:(UIViewController *)vc path:(NSString *)path;
1
2
3
4
5
6
/// MP4续播
/// @param path MP4回放地址
/// @param controller 代理
/// @param skipTime 时间点 (选填 可传" ")
/// @param breakurl breakurl (选填 可传" ")
- (void)joinRoomWithPlaybackPath:(NSString*)path ViewController:(UIViewController*)controller skipTime:(NSString *)skipTime breakurl:(NSString *)breakurl;

f.展示设备检测页面:

1
2
3
/// 展示设备检测页面
/// @param vc 控制器用于弹出设备检测页面
-(void)showDeviceStatusCheck:(UIViewController *)vc;

5. 插件-友盟分享(可选)

添加分享功能(友盟)

5.1 、pod 集成友盟插件
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
pod 'UMCommon', '7.2.5'
pod 'UMShare/UI', '6.10.1'
# 微信完整版
pod 'UMShare/Social/WeChat', '6.10.1'

/// QQ 新浪 暂未开通
# 集成QQ/QZone/TIM(完整版7.6M)
pod 'UMShare/Social/QQ', '6.10.1'
# 集成新浪微博(完整版25.3M)
pod 'UMShare/Social/Sina', '6.10.1'
5.2 、添加文件

将 demo 中 TKUIDEMO -> PluginClass 文件夹添加到工程中

5.3 、添加代码(需要提前准备 友盟、微信等平台账号,并填写相关信息获取 相关参数)(相关问题可以自行百度)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // 添加
    [self addTKSharePlugin];

    return YES;
}

- (void) addTKSharePlugin {

    // 友盟分享(如果使用需要完成以下内容)
    // 1 pod 集成相关UM库(参考podfile)
    // 2 在 UM 和 微信 平台创建账号并申请权限(当前版本只支持分享到微信好友和朋友圈)并完成相关配置
    // 3 填写 TKUMShareSettings 分享内相关宏定义的值.   APP启动时调用 [TKUMShareSettings UMShareSettings] 初始化分享,
    [TKUMShareSettings UMShareSettings];

    // 进入教室前 设置分享回调
    _sharePlugin = [[TK_SharePlugin alloc] init];
    [[TKAPPSetConfig shareInstance] registerSharePlusin:_sharePlugin];
}

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{

    if ([url.relativeString containsString:@"enterroomnew://"]) {
        [[TKEduClassManager shareInstance] joinRoomWithUrl:url.relativeString];
        [TKEduClassManager shareInstance].isUrlOpen = YES;//记录外部链接打开
    } else {
#if __has_include(<UMShare/UMShare.h>)
        //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
        BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
        if (result == NO) {

        }
        return result;
#else
#endif
    }
    return YES;
}

#if __has_include(<UMShare/UMShare.h>)
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {

    if (![[UMSocialManager defaultManager] handleUniversalLink:userActivity options:nil]) {
        // 其他SDK的回调
    }
    return YES;
}
#else
#endif
5.5 、拓课云后台配置分享内容 (icon、url、text 等),配置好后创建的教室将携带相关信息,原有教室不携带。

6. 屏幕旋转问题处理

6.1 、 Xcode配置

TARGETS -> General -> Deployment Info -> Device Orientation 勾选 Portrait、 Landscape Left、Landscape Right。

6.2 、 AppDelegate.m 中添加

* 代码优先级高于Xcode配置 防止内部代码覆盖Xcode配置

1
2
3
4
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    return UIInterfaceOrientationMaskAll;
}

6.3 、 RootViewController 设置 (代码示例)

* 根据自己业务需求在跳转UISDK的ViewController设置屏幕方向

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- (BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    if (IS_IPHONE) {
        return UIInterfaceOrientationMaskPortrait;
    }
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    UIInterfaceOrientation interfaceOriention = [UIApplication sharedApplication].statusBarOrientation;
    if (IS_IPHONE) {
        return UIInterfaceOrientationPortrait;
    }
    if (interfaceOriention == UIInterfaceOrientationLandscapeLeft) {
        return UIInterfaceOrientationLandscapeLeft;
    }else {
        return UIInterfaceOrientationLandscapeRight;
    }
}

7. 配置桌面共享

7.1 、主工程下新建 TARGETS

1 、创建拓展工程

2 、拓展工程配置 Build Settings -> Enable Bitcode -> NO

7.2 、创建 App Groups

1 、主工程与拓展工程勾选相同的 App Groups 完成两者之间通信

7.3 、添加依赖库及代码

1 、导入 TKScreenShareService.framework 复制 Demo 工程 SampleHandler 文件代码,并将 init 方法内 AppGroup 传参改为你所创建的 Group 名称(如图)

2 、拓展工程添加依赖库

Deployment info iOS 支持版本需设置为 iOS12

3 、主工程添加依赖库 TKScreenShareService.framework (如图)

8. 常见问题描述

8.1 、进入教室出现错误码
1
(TKEduRoomDelegate -> - (void)onEnterRoomFailed:(int)result Description:(NSString*)desc;)
错误码 说明
3001 服务器过期
3002 公司被冻结
3003 课堂被删除或过期
4007 课堂不存在
4008 课堂密码错误
4103 课堂人数超限
4110 该课堂需要密码,请输入密码

(在此只列举部分错误码,更详细错误码请参考 TKRoomSDK.framwork 中的 TKRoomDefines 类。)

8.2 、获取录制件接口(回放 path 参数获取方式): getrecordlist

请求 URL: https://global.talk-cloud.net/WebAPI/getrecordlist 请求方式:POST

参数:

参数 必选 类型 说明
key String 企业 key
serial String 房间号
thirdroomid String 第三方教室号:和 serial 二选一必填
starttime int 开始时间(时间截:1597852800)
endtime int 结束时间(时间截:1597852800)
recordtype int 返回录制件类型(0 常规,1mp4,2 所有),默认只返回常规

返回示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
    "result": 0,
    "recordlist": [
        {
            "recordid": "1000610044773851543565780miarfiuv",
            "serial": "10044277385",
            "companyid": "100026",
            "recordtitle": "1543565779986",
            "starttime": "1543565780",
            "duration_ms": 1394883,
            "size": "432722377",
            "webhost": "https://local.global.com",
            "recordpath": "/0904754e-f255-4070-8075-c99f517adbb8-1004477385/",
            "state": "0",
            "playpath": "http://local.global.com/replay/1004477385/10006/1543565779986/",
            "https_playpath": "https://local.global.com/replay/1004477385/10006/1543565779986/"
        },
        {
            "recordid": "10108013994234561603071801rtvsdgju",
            "serial": "10044277385",
            "companyid": "100026",
            "recordtitle": "1603071800847",
            "starttime": "1603071801",
            "duration_ms": 2234,
            "size": "1368886",
            "webhost": "https://local.global.com",
            "recordpath": "/700ef742-f37a-4932-a85c-be5e4dcf09bf-1399423456/",
            "state": "0",
            "playpath": "",
            "https_playpath": "",
            "playpath_mp4": "http://record.talk-cloud.net/700ef742-f37a-4932-a85c-be5e4dcf09bf-1399423456/record.mp4",
            "https_playpath_mp4": "https://record.talk-cloud.net/700ef742-f37a-4932-a85c-be5e4dcf09bf-1399423456/record.mp4",
            "playpath_m4a": "",
            "https_playpath_m4a": "",
            "videoplayback_m4a": "",
            "videoplayback_mp4": "https://global.talk-cloud.net/media/1399423456/101080/1603071800847/1/"
        }
    ]
}

返回参数说明

参数 类型 说明
recordlist.recordid String 录制件 ID
recordlist.serial String 房间号
recordlist.companyid String 企业 ID
recordlist.recordtitle String 录制标题
recordlist.starttime String 开始时间
recordlist.duration_ms Int 时长(毫秒)
recordlist.size String 录制件大小
recordlist.webhost String 访问域名
recordlist.recordpath String 录制件路径
recordlist.state String 录制件状态
recordlist.playpath String 常规播放地址
recordlist.https_playpath String https 常规播放地址
recordlist.playpath_mp4 String MP4 播放地址
recordlist.https_playpath_mp4 String httpsMP4 播放地址
recordlist.playpath_m4a String M4A 播放地址
recordlist.https_playpath_m4a String httpsM4A 播放地址
recordlist.videoplayback_mp4 String 视频播放地址
recordlist.videoplayback_m4a String 音频播放地址

常规录制件 path 参数拼接方法

获取录制件,生成录制件(recordtype=0 convert = 1) 的时候。调用 getrecordlist 接口去获取 recordpath 播放回放的参数 path global.talk-cloud.net:8081 + recordpath 例: global.talk-cloud.net:8081/bb3ae4f7-1242-4752-a7bb-afe8f3f1ab87-1695310935/

8.3 、通过 Cocoapods 导入的第三方库:参考 Podfile 文件.

如果使用到友盟,

SDK 版本需要一致(当前:UMCommon 7.2.5 UMShare 6.10.1)否则会版本冲突导致闪退 SDK 名称需要一致(UMCommon / UMCCommon)

1
2
3
4
5
6
7
8
9
  pod 'UMCommon', '7.2.5'

  pod 'UMShare/UI', '6.10.1'
  # 微信完整版
  pod 'UMShare/Social/WeChat', '6.10.1'
  # 集成QQ/QZone/TIM(完整版7.6M)
  pod 'UMShare/Social/QQ', '6.10.1'
  # 集成新浪微博(完整版25.3M)
  pod 'UMShare/Social/Sina', '6.10.1'
8.4 、本地语言简体中文 地区中国大陆 进入教室显示英文问题 添加本地支持支持语言
1
2
3
targets -> Info -> Custom iOS Target Properties
添加 Localizations(类型:Array
内容: Chinesetraditional)、Chinese(simplified)English 三项