摄像机

更新时间:2023-09-19 03:00:53下载pdf

通过家庭查询到设备列表后,就可以根据设备的类型来判断是否是智能摄像机设备。如果是智能摄像机设备,则可以根据 ThingSmartDeviceModel 中的信息来创建摄像机对象。

判断是否是摄像机

通过 ThingSmartDeviceModel+IPCSDK 分类中的接口,可以判断设备是否是摄像机。

接口说明

判断是否具有 IPC 高级能力,不可用作设备品类判断。

对于一些融合品类,除了自身功能外还附带 IPC 高级能力,例如可视门锁。

- (BOOL)isIPCDevice;

示例代码

Objective C:

[[ThingSmartHomeManager new] getHomeListWithSuccess:^(NSArray<ThingSmartHomeModel *> *homes) {
        [homes enumerateObjectsUsingBlock:^(ThingSmartHomeModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                ThingSmartHome *home = [ThingSmartHome homeWithHomeId:obj.homeId];
                [home getHomeDetailWithSuccess:^(ThingSmartHomeModel *homeModel) {
                        [home.deviceList enumerateObjectsUsingBlock:^(ThingSmartDeviceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if ([obj isIPCDevice]) {
                        NSLog(@"%@ 是一个智能摄像机设备", obj.name);
                    }
        }];
        } failure:^(NSError *error) {

        }];
    }];
} failure:^(NSError *error) {

}];

Swift:

let homeManager = ThingSmartHomeManager()
homeManager.getHomeList(success: { homeList in
    homeList?.forEach({ homeModel in
        let home = ThingSmartHome(homeId: homeModel.homeId)
        home?.getDetailWithSuccess({ _ in
            home?.deviceList.forEach({ deviceModel in
                if deviceModel.isIPCDevice() {
                    print(deviceModel.name!, "是一个智能摄像机设备")
                }
            })
        }, failure: { error in

        })
    })
}) { error in

}

示例代码只是展示具有 IPC 高级能力设备的最简单流程,实际开发中,您需要根据 UI 交互的逻辑来展示和管理设备。

摄像机实例

类(协议)说明

类名(协议名) 说明
ThingSmartCameraFactory 创建摄像机配置和摄像机对象的工具类
ThingSmartCameraConfig 摄像机配置类,您无需关心它的属性
ThingSmartCameraType 摄像机接口协议,根据摄像机固件类型不同,有不同的具体实现
ThingSmartCameraDelegate 摄像机代理,摄像机功能方法的结果反馈都将通过代理方法回调

ThingSmartCameraFactory 提供创建摄像机控制对象的工厂方法。

接口说明

创建摄像机实例对象。

+ (id<ThingSmartCameraType>)cameraWithP2PType:(id)type deviceId:(NSString *)devId delegate:(id<ThingSmartCameraDelegate>)delegate;

参数说明

参数 说明
type P2P 类型,参数使用 Number 类型
devId 设备 ID
delegate 代理对象

返回值

类型 说明
id 摄像机接口的具体实现对象

查询 P2P 类型

IPC SDK 会根据 P2P 类型来初始化不同摄像机具体实现的对象,通过 ThingSmartDeviceModel+IPCSDK 中的接口可以查询设备的 P2P 类型。涂鸦智能摄像机支持三种类型的 P2P 通道实现方案。

接口说明

查询 P2P 类型。

- (NSInteger)p2pType;

示例代码

Objective C:

// deviceModel 为设备列表中的摄像机设备的数据模型
id<ThingSmartCameraType> camera = [ThingSmartCameraFactory cameraWithP2PType:@(deviceModel.p2pType) deviceId:deviceModel.devId delegate:self];

Swift:

let camera = ThingSmartCameraFactory.camera(withP2PType: deviceModel.p2pType(), deviceId: deviceModel.devId, delegate: self)

示例代码中,delegate 参数传入的 self 需要实现 ThingSmartCameraDelegate 协议。