更新时间:2024-11-18 11:32:37下载pdf
门锁音视频能力接口支持可视门锁、拍照锁的实时视频查看、对讲等功能。
| 类名 | 说明 | 
|---|---|
TuyaSmartWiFiLockDevice | 
封装音视频能力的 Wi-Fi 门锁设备操作类,继承自 TuyaSmartDevice | 
TuyaSmartWiFiLockDeviceDelegate | 
Wi-Fi 门锁设备协议代理,拓展自 TuyaSmartDeviceDelegate | 
代理说明
TuyaSmartWiFiLockDeviceDelegate:
/// 设备传图数据上报 dp212
///
/// @param device 门锁设备
/// @param message 设备上报的数据
- (void)onLockMessageArrived:(TuyaSmartWiFiLockDevice *)device
                     message:(NSDictionary *)message;
/// 实时视频上报回调 dp63
///
/// @param device 门锁设备
/// @param model 设备上报的数据
- (void)onVideoRequestRealtime:(TuyaSmartWiFiLockDevice *)device
                         model:(NSString *)model;
/// 远程开门请求图片上报 dp9
///
/// @param device 门锁设备
/// @param time 倒计时数据
- (void)unlockRequestCountdown:(TuyaSmartWiFiLockDevice *)device
                          time:(NSInteger)time;
/// 告警请求图片上报 dp45
///
/// @param device 门锁设备
/// @param time 倒计时数据
- (void)alarmRequestCountdown:(TuyaSmartWiFiLockDevice *)device
                         time:(NSInteger)time;
/// 远程开门回复上报 dp50
///
/// @param device 门锁设备
- (void)onRemoteUnlockReport:(TuyaSmartWiFiLockDevice *)device;
/// 强制反锁回复上报 dp13
///
/// @param device 门锁设备
- (void)onForceLockUpReport:(TuyaSmartWiFiLockDevice *)device;
示例代码
//初始化
self.lockDevice = [[TuyaSmartWiFiLockDevice alloc] initWithDeviceId:self.device.deviceModel.devId];
//设置代理
self.lockDevice.delegate = self;
//远程请求开门 dp63
- (void)onVideoRequestRealtime:(TuyaSmartWiFiLockDevice *)device model:(NSString *)model{
    //TODO
}
//设备传图数据 dp212
- (void)onLockMessageArrived:(TuyaSmartWiFiLockDevice *)device message:(nonnull NSDictionary *)message{
    //TODO
}
//远程开门请求图片 dp9
- (void)unlockRequestCountdown:(TuyaSmartWiFiLockDevice *)device time:(NSInteger)time{
    //TODO    
}
//告警请求图片 dp45
- (void)alarmRequestCountdown:(TuyaSmartWiFiLockDevice *)device time:(NSInteger)time{
    //TODO
}
//远程开门回复上报 dp50
- (void)onRemoteUnlockReport:(TuyaSmartWiFiLockDevice *)device{
    //TODO
}
//强制反锁回复上报 dp13
- (void)onForceLockUpReport:(TuyaSmartWiFiLockDevice *)device{
    //TODO
}
接口说明
通过此接口可以实现远程开锁、关锁、拒绝开锁、拒绝关锁。
- (void)remoteLockWithDevId:(NSString *)devId
                       open:(BOOL)open
                    confirm:(BOOL)confirm
                    success:(nullable TYSuccessBOOL)success
                    failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| devId | 设备 ID | 
| open | 开门还是关门,开门=YES,关门=NO | 
| confirm | 允许还是拒绝,允许=YES,拒绝=NO | 
| success | 接口成功回调 | 
| failure | 接口失败回调 | 
success 回调只能表示接口调用成功,不能作为门锁设备执行指令判断标准。
confirm = YES 时,设备状态发生变化(开锁、关锁)。设备执行成功后,依赖监听方法 onRemoteUnlockReport 回调结果。confirm=NO 时,设备状态没有产生变化,不会上报 DP 状态。success 表示拒绝开锁或拒绝关锁的任务执行成功。示例代码
    [self.lockDevice remoteLockWithDevId:devId
                                    open:YES
                                 confirm:NO
                                 success:^(BOOL result) {
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];
接口说明
重新拍照。设备会把抓拍的图片传到云存储,并通过 onLockMessageArrived 上报图片路径信息。受设备限制,15 秒内只能下发一次。
- (void)reTakePhoto:(BOOL)needTake
            success:(TYSuccessHandler)success
            failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| needTake | 是否重新拍照 | 
| success | 接口成功回调 | 
| failure | 接口失败回调 | 
示例代码
[self.lockDevice reTakePhoto:YES success:^{
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];
接口说明
强制反锁。设备执行成功会通过 onForceLockUpReport 回调结果。
- (void)enforceLock:(BOOL)needLock
            success:(TYSuccessHandler)success
            failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| needLock | 是否强制反锁 | 
| success | 接口成功回调 | 
| failure | 接口失败回调 | 
示例代码
[self.lockDevice enforceLock:YES
                         success:^{
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];
接口说明
获取云存储上最新的一张图片信息。需要与接口 getPopupPictureAddressWithDevId 配合使用。
- (void)getLatestPopupInfoWithDevId:(NSString *)devId
                           fileType:(NSInteger)fileType
                            success:(nullable TYSuccessID)success
                            failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| devId | 设备 ID | 
| fileType | 图片类型:远程解锁抓拍图片、告警抓拍图片 | 
| success | 接口成功回调 | 
| failure | 接口失败回调 | 
返回值说明
| 字段 | 说明 | 
|---|---|
| filePath | 图片在云存储的路径 | 
| fileKey | 解密 Key | 
| bucket | 云存储 Bucket | 
示例代码
    [self.lockDevice getLatestPopupInfoWithDevId:self.lockDevice.deviceModel.devId
                                        fileType:1
                                         success:^(id result) {
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];
接口说明
设备抓拍的图片会上传到云存储,通过此接口获取图片的地址。与监听回调 onLockMessageArrived 方法或 getLatestPicture 配合使用。
- (void)getPopupPictureAddressWithDevId:(NSString *)devId
                                 bucket:(NSString *)bucket
                               filePath:(NSString *)filePath
                               success:(nullable TYSuccessID)success
                               failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| devId | 设备 ID | 
| bucket | 云存储 Bucket | 
| filePath | 云存储加密 URL | 
| success | 接口成功回调 | 
| failure | 接口失败回调 | 
返回值说明
| 字段 | 说明 | 
|---|---|
| fileUrl | 图片在云存储的路径 | 
| mediaUrl | 视频在云存储的路径 | 
| angle | 角度,在涂鸦开发者平台配置的角度旋转,有效值:0、90、180、270。 | 
fileUrl 仍然是加密链接,需要 onLockMessageArrived 或 getLatestPopupInfoWithDevId 获取 fileKey 解密。涂鸦提供控件 TYEncryptImage 负责解密和显示图像。
示例代码
//查询封面图地址
[self.lockDevice getPopupPictureAddressWithDevId:self.lockDevice.deviceModel.devId
                                          bucket:bucket
                                        filePath:filePath
                                         success:^(id result) {
            NSInteger angle = [result[@"angle"] integerValue];
            NSString *fileUrl = result[@"fileUrl"];
        } failure:^(NSError *error) {
            
        }];
//解密图片链接后获取image
UIImageView *imageView = [UIImageView new];
[imageView ty_setAESImageWithPath:fileUrl
                       encryptKey:fileKey
                        completed:^(UIImage * _Nullable image, NSURL * _Nullable url, TYEncryptWebImageFromType from, TYEncryptWebImageStage stage, NSError * _Nullable error) {
        //TODO
    }];
属性说明
@property (nonatomic, strong, readonly) id<TuyaSmartCameraType> cameraType; // camera 对象。
在开始视频播放之前,需要先连接 P2P 通道。P2P 状态需要使用者自行维护,SDK 只负责下发指令和接收摄像机响应结果。
接口说明
- (void)p2pConnect;
- (void)p2pDisConnect;
- (BOOL)isP2pConnected;
- (BOOL)isP2pConnecting;
P2P 连接成功之后,即可进行实时视频播放。
接口说明
- (void)startPreviewWithDefinition:(TuyaSmartCameraDefinition)definition
- (void)stopPreview;
参数说明
| 参数 | 说明 | 
|---|---|
| definition | 清晰度模式 | 
清晰度模式
| 模式 | 值 | 
|---|---|
| 标清 | 0x2 | 
| 高清 | 0x4 | 
示例代码
[self.lockDevice startPreviewWithDefinition:TuyaSmartCameraDefinitionStandard];
当视频成功开始播放以后(可以是视频直播,也可以是录像回放),可以将当前正在播放的视频录制到手机中。
在视频录制的过程中,请不要再切换视频清晰度、开关声音及对讲。
接口说明
- (void)startRecordWithRotateDirection:(TuyaSmartVideoRotateDirection)direction
                              filePath:(NSString *)filePath;
录制视频需要相册读写权限。
参数说明
| 参数 | 说明 | 
|---|---|
| direction | 旋转角度 | 
| filePath | 指定存储目录 | 
接口说明
- (void)stopRecordAndFetchPath;
接口说明
- (BOOL)isRecording;
示例代码
    if ([self.lockDevice isRecording]) {
        [self.lockDevice stopRecordAndFetchPath];
    }else{
        [self.lockDevice startRecordWithRotateDirection:TuyaSmartVideoRotateDirectionUp filePath:@"存储目录"];
    }
截取实时视频的图片后,需要用户自行将图片存储到手机相册里。
接口说明
- (UIImage *)snapShootWithRotateDirection:(TuyaSmartVideoRotateDirection)direction
                              savedAtPath:(NSString *)filePath
                             thumbnilPath:(NSString *)thumbnilPath;
参数说明
| 参数 | 说明 | 
|---|---|
| direction | 旋转角度 | 
| filePath | 指定存储目录 | 
| thumbnilPath | 缩略图 | 
示例代码
[self.lockDevice snapShootWithRotateDirection:TuyaSmartVideoRotateDirectionUp savedAtPath:@"存储目录" thumbnilPath:nil];
当视频成功开始播放以后,可以开启视频声音。声音默认是关闭状态。
接口说明
开启、关闭视频声音。
- (void)enableMute:(BOOL)mute;
| 音频模式 | 值 | 
|---|---|
| mute | 
  | 
- (BOOL)isMuting;
示例代码
BOOL isMuted = [self.lockDevice isMuting];
[self.lockDevice enableMute:!isMuted];
在 P2P 连接成功后,可以开启与设备的实时通话功能。在开始对讲前,需要确保 App 已获得手机麦克风的访问权限。
打开手机声音传输给摄像机操作。
- (void)startTalk;
关闭手机声音传输给摄像机操作。
- (void)stopTalk;
设备是否对讲中。
- (BOOL)isTalking;
设备是否支持对讲。
- (BOOL)isSupportedTalk;
- (BOOL)isTalking;
示例代码
    BOOL isTalking = [self.lockDevice isTalking];
    BOOL isSupportedTalk = [self.lockDevice isSupportedTalk];
    if (isSupportedTalk) {
        if (isTalking) {
            [self.lockDevice stopTalk];
        }else{
            [self.lockDevice startTalk];
        }
    }
接口说明
设备是否有拾音器。若设备配置有拾音器,表示设备的视频有声音。
- (BOOL)isSupportedSound;
接口说明
获取默认的对讲方式。
- (TuyaSmartCameraTalkbackMode)supportedAudioMode;
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈