第一步:集成
平台支持
| 平台 | SDK 及兼容性 | SDK 及 Demo | 
| iOS | Xcode 10.2+, iOS 9.0+ | 1.  填写 申请表 进行申请。 2. 完成申请后,相关工作人员将联系您进行需求沟通,并提供对应 SDK 及 Demo。 | 
将 IoT Video(Consumer Version) SDK 集成到您的项目中并配置工程依赖,即可完成 SDK 的集成工作。
第二步:接入准备
说明:
开始使用 SDK 前,我们还需要获取
AccessId和AccessToken,获取方式如下:AccessId: 指外部访问 IoT Video(Consumer Version) 云平台的唯一性身份标识。
AccessToken: 登录成功后 IoT Video(Consumer Version) 云服务器返回的
AccessToken。1. 获取 AccessId
用户自有账号体系可以采用云对接的方式实现账户体系相关业务,详情请参见 终端用户注册。
2. 获取 AccessToken
用户自有账号体系可以采用云对接的方式实现账户体系相关业务,详情请参见 终端用户接入授权。
第三步:SDK 初始化
1. 初始化
在 
AppDelegate 中的application:didFinishLaunchingWithOptions:调用如下初始化方法:import IoTVideo@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) {// 初始化IoTVideo.sharedInstance.setup(launchOptions: launchOptions)// 设置代理IoTVideo.sharedInstance.delegate = self// 设置日志等级IoTVideo.sharedInstance.logLevel = .DEBUG...}}/// 实现IoTVideoDelegate协议extension AppDelegate: IoTVideoDelegate {// SDK状态回调func didUpdate(_ linkStatus: IVLinkStatus) {print("sdkLinkStatus: \\(linkStatus.rawValue)")}// SDK日志输出func didOutputPrettyLogMessage(_ message: String) {print(message)}}
2. 注册
账号注册成功后可获取到 
accessId,登录成功后可获取到 accessToken,调用 SDK 注册接口:import IoTVideoIoTVideo.sharedInstance.register(withAccessId: "********", accessToken: "********")
对设备的操作都依赖于
accessId和accessToken的加密校验,非法参数将无法操作设备。第四步:配网
通过 SDK 初始化我们已经可以正常使用 SDK,现在我们为设备配置上网环境。
1. 设备联网
设备配网模块用来为设备配置上网环境,目前支持以下配网方式:
有线配网
扫码配网
AP 配网
注意:
2. 设备绑定
设备绑定具体操作请参见 终端用户绑定设备接口 进行设备绑定。
3. 设备订阅
绑定成功后,获取到订阅 Token,需调用命令使 IoT Video(Consumer Version) SDK 订阅该设备:
IVNetConfig.subscribeDevice(withToken: "********", deviceId: deviceId)
第五步:监控
使用内置的多媒体模块可以轻松实现设备监控。
import IoTVideo// 1.创建监控播放器let monitorPlayer = IVMonitorPlayer(deviceId: device.deviceID)// 如果是多源设备(NVR),创建监控播放器时应指定源ID,例如"2"// let monitorPlayer = IVMonitorPlayer(deviceId: device.deviceID, sourceId: 2)// 2.设置播放器代理(回调)monitorPlayer.delegate = self// 3.添加播放器渲染图层videoView.insertSubview(monitorPlayer.videoView!, at: 0)monitorPlayer.videoView?.frame = videoView.bounds// 4.预连接,获取流媒体头信息【此步骤可跳过】monitorPlayer.prepare()// 5.开始播放,启动推拉流、渲染模块monitorPlayer.play()// 6.开启/关闭语音对讲(只支持MonitorPlayer/LivePlayer)monitorPlayer.startTalking()monitorPlayer.stopTalking()// 7.停止播放,断开连接monitorPlayer.stop()
第六步:消息管理
import IoTVideo.IVMessageMgr// 设备ID的字符串let deviceId = dev.deviceId// 模型路径的字符串let path = "ProWritable._logLevel"// 模型参数的字符串let json = "{\\"setVal\\":0}"// 1.读取属性IVMessageMgr.sharedInstance.readProperty(ofDeviceId: deviceId, path: path) { (json, error) in// do something here}// 2.设置属性IVMessageMgr.sharedInstance.writeProperty(ofDevice:deviceId, path: path, json: json) { (json, error) in// do something here}// 3.执行动作// 模型路径的字符串let actionPath = "Action.cameraOn"// 模型参数的字符串let actionJson = "{\\"ctlVal\\":1}"IVMessageMgr.sharedInstance.takeAction(ofDevice: deviceId, path: actionPath, json: actionJson) { (json, error) in// do something here}