更新时间:2023-06-12 07:51:09下载pdf
| 类名 | 说明 | 
|---|---|
| TuyaSmartBLELockDevice | 蓝牙门锁设备操作类,继承自 TuyaSmartDevice | 
| TuyaSmartBLELockDeviceDelegate | 蓝牙门锁设备协议代理,拓展自 TuyaSmartDeviceDelegate | 
| 名词列表 | 说明 | 
|---|---|
| 门锁劫持 | 指将特定的指纹、密码等,设置为劫持密码,当用户被劫持,并使用该密码开锁时,门会打开。同时,门锁将开门报警信息发送至家人手机或物业管理系统。 | 
| 门锁成员 | 门锁成员分为 家庭成员 与 非家庭成员: 
 | 
| lockUserId | 创建门锁成员时,云端为设备分配的固件成员 ID,代表着固件内记录的用户 ID。 | 
| userId | 创建门锁成员时,云端分配的数据库记录 ID,代表着用户的唯一 ID。 | 
| dpCode | 设备功能的标识符。每个设备功能都有对应的名称和编号,可参考 门锁功能列表。 | 
本小节介绍门锁成员中 非家庭成员 的管理操作。
接口说明
- (void)getMemberListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockMemberModel *> *members))success
                         failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| success | 成功回调,成员列表 | 
| failure | 失败回调 | 
TuyaSmartBLELockMemberModel 数据模型
| 字段 | 类型 | 描述 | 
|---|---|---|
| userId | NSString | 成员编号 ID | 
| userContact | NSString | 联系方式 | 
| avatarUrl | NSString | 头像地址 | 
| nickName | NSString | 成员名称 | 
| userTimeSet | NSString | 成员时效性数据 | 
| phase | NSUInteger | 冻结情况 
 | 
| status | NSUInteger | 用户状态 | 
| lockUserId | int | 门锁上的用户 ID | 
| userType | NSUInteger | 用户类型 
 | 
| supportOpenType | NSArray | 支持的开锁方式 | 
| shareUser | NSString | 分享的用户账号 | 
| productAttribute | NSUInteger | 设备产品属性 | 
示例代码
Objective-C:
[self.lock getMemberListWithSuccess:^(NSArray<TuyaSmartBLELockMemberModel *> * _Nonnull list) {
    NSLog(@"成员列表 %@", list);
} failure:^(NSError *error) {
    NSLog(@"获取成员列表失败,error: %@", error);
}];
Swift:
self.lock?.getMemberList(success: { (list) in
    print("成员列表 \(list)")
}, failure: { (error) in
    if let e = error {
        print("获取成员列表失败, error: \(e)")
    }
})
创建非家庭成员,后续可以单独为该成员绑定解锁方式。

接口说明
- (void)addMemberWithUserName:(NSString *)userName
                  allowUnlock:(BOOL)allowUnlock
                     timeType:(TYMemberTimeType)timeType
                effectiveDate:(NSDate *)effectiveDate
                  invalidDate:(NSDate *)invalidDate
                      success:(nullable TYSuccessBOOL)success
                      failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| userName | 成员名称 | 
| allowUnlock | 是否允许成员使用蓝牙解锁 | 
| timeType | 时效性 
 | 
| effectiveDate | 生效时间 | 
| invalidDate | 失效时间 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock addMemberWithUserName:#<成员名称># allowUnlock:YES timeType:TYMemberTimeTypePhase effectiveDate:[NSDate date] invalidDate:[[NSDate date] dateByAddingTimeInterval:60 * 60 * 8] success:^(BOOL result) {
    NSLog(@"创建门锁成员成功");
} failure:^(NSError *error) {
    NSLog(@"创建门锁成员失败,error: %@", error);
}];
Swift:
self.lock?.addMember(withUserName: "name", allowUnlock: true, timeType: .phase, effectiveDate: Date(), invalidDate: Date().addingTimeInterval(60 * 60 * 8), success: { (result) in
    print("创建门锁成员成功")
}, failure: { (error) in
    if let e = error {
        print("创建门锁成员失败, error: \(e)")
    }
})
修改门锁成员信息会和硬件进行交互,需要门锁保持蓝牙连接。

接口说明
- (void)updateMemberWithUserName:(NSString *)userName
                        memberId:(NSString *)memberId
                     allowUnlock:(BOOL)allowUnlock
                        timeType:(TYMemberTimeType)timeType
                   effectiveDate:(NSDate *)effectiveDate
                     invalidDate:(NSDate *)invalidDate
                         success:(nullable TYSuccessBOOL)success
                         failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| userName | 成员名称 | 
| memberId | 成员 ID | 
| allowUnlock | 是否允许使用蓝牙解锁 | 
| timeType | 时效性 
 | 
| effectiveDate | 生效时间 | 
| invalidDate | 失效时间 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock updateMemberWithUserName:@"new name" memberId:@"0000008byw" allowUnlock:YES timeType:TYMemberTimeTypePermanent effectiveDate:[NSDate date] invalidDate:[[NSDate date] dateByAddingTimeInterval:60 * 60 * 8] success:^(BOOL result) {
    NSLog(@"更新门锁成员成功");
} failure:^(NSError *error) {
    NSLog(@"创建门锁成员失败,error: %@", error);
}];
Swift:
self.lock?.updateMember(withUserName: "new name", memberId: "0000008byw", allowUnlock: true, timeType: .phase, effectiveDate: Date(), invalidDate: Date().addingTimeInterval(60 * 60 * 8), success: { (result) in
        print("更新门锁成员信息成功")
    }, failure: { (error) in
        if let e = error {
            print("更新门锁成员信息失败, error: \(e)")
        }
    })
删除门锁成员会和硬件进行交互,会删除该用户下所有的开锁方式、密码等,需要门锁保持蓝牙连接。

接口说明
- (void)removeMemberWithMemberId:(NSString *)memberId
                         success:(nullable TYSuccessBOOL)success
                         failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| memberId | 成员编号 ID | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock removeMemberWithMemberId:@"000000747d" success:^(BOOL result) {
    NSLog(@"删除门锁成员成功");
} failure:^(NSError *error) {
    NSLog(@"删除门锁成员失败, error: %@", error);
}];
Swift:
self.lock?.removeMember(withMemberId: "", success: { (result) in
    print("删除门锁成员成功")
}, failure: { (error) in
    if let e = error {
        print("删除门锁成员失败, error: \(e)")
    }
})
蓝牙门锁需要 App 开启蓝牙后,部分功能才能正常使用。SDK 在正常情况下会自动连接,通常使用以下方法进行门锁连接状态判断。
接口说明
/// 如果没有连接成功或使用过程中断开,可以调用此方法进行连接
- (void)autoConnect;
/// 门锁和手机是否已建立蓝牙连接,如果为 NO,可以调用 autoConnect 进行连接
- (BOOL)isBLEConnected;
获取动态密码。
接口说明
- (void)getLockDynamicPasswordWithSuccess:(nullable TYSuccessString)success
                                  failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| success | 接口成功回调,返回结果为对应获取的动态密码 | 
| failure | 接口失败回调 | 
示例代码
Objective-C:
TuyaSmartBLELockDevice *lock = [TuyaSmartBLELockDevice deviceWithDeviceId:@"your_lock_device_id"];
[lock getLockDynamicPasswordWithSuccess:^(NSString *result) {
    NSLog(@"动态密码获取结果 %@", result);
} failure:^(NSError *error) {
    NSLog(@"error %@", error);
}];
Swift:
let lockDevice = TuyaSmartBLELockDevice(deviceId: "your_lock_device_id")
lockDevice?.getLockDynamicPassword(success: { (pwd) in
    print("动态密码获取结果 \(pwd)")
}, failure: { (error) in
    if let e = error {
        print("error \(e)")
    }
})

接口说明
- (void)unlockWithStatus:(BOOL)status
                 success:(nullable TYSuccessHandler)success
                 failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| status | 开锁或者关锁状态 | 
| success | 接口成功回调 | 
| failure | 接口失败回调 | 
示例代码
Objective-C:
TuyaSmartBLELockDevice *lock = [TuyaSmartBLELockDevice deviceWithDeviceId:@"your_lock_device_id"];
BOOL status = YES;
[lock unlockWithStatus:status success:^{
    NSLog(@"开锁成功");
} failure:^(NSError *error) {
    NSLog(@"开锁失败,error %@", error);
}];
Swift:
let lockDevice = TuyaSmartBLELockDevice(deviceId: "your_lock_device_id")
self.lock?.unlock(withStatus: status, success: {
    print("开锁成功")
}, failure: { (error) in
    if let e = error {
        print("开锁失败,error: \(e)")
    }
})

接口说明
- (void)manualLockWithStatus:(BOOL)status
                     success:(TYSuccessHandler)success
                     failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| status | 开锁还是关锁 | 
| success | 接口成功回调 | 
| failure | 接口失败回调 | 
示例代码
Objective-C:
TuyaSmartBLELockDevice *lock = [TuyaSmartBLELockDevice deviceWithDeviceId:@"your_lock_device_id"];
BOOL status = YES;
[lock manualLockWithStatus:status success:^{
    NSLog(@"落锁成功");
} failure:^(NSError *error) {
    NSLog(@"落锁失败,error %@", error);
}];
Swift:
let lockDevice = TuyaSmartBLELockDevice(deviceId: "your_lock_device_id")
self.lock?.manualLock(withStatus: status, success: {
    print("落锁成功")
}, failure: { (error) in
    if let e = error {
        print("落锁失败,error: \(e)")
    }
})
接口说明
- (void)getAlarmRecordListWithOffset:(int)offset
                               limit:(int)limit
                             success:(nullable void(^)(NSArray<TuyaSmartLockRecordModel *> *records))success
                             failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| offset | 页数 | 
| limit | 条数 | 
| success | 成功回调,结果为记录列表 | 
| failure | 失败回调 | 
TuyaSmartLockRecordModel 数据模型
| 字段 | 类型 | 描述 | 
|---|---|---|
| userId | NSString | 成员 ID | 
| userName | NSString | 用户昵称 | 
| time | NSTimeInterval | 发生时间,13 位时间戳 | 
| devId | NSString | 设备 ID | 
| dpData | NSDictionary | DP 数据 | 
| tags | NSInteger | 标位 
 | 
| dpsArray | NSArray<NSDictionary *> | 设备功能的数据组 | 
示例代码
Objective-C:
[self.lock getAlarmRecordListWithOffset:0 limit:50 success:^(NSArray<TuyaSmartLockRecordModel *> * _Nonnull records) {
    NSLog(@"告警记录: %@", records);
} failure:^(NSError *error) {
    NSLog(@"获取告警记录失败,error: %@", error);
}];
Swift:
self.lock?.getAlarmRecordList(withOffset: 0, limit: 50, success: { (records) in
    print("告警记录 \(records)")
}, failure: { (error) in
    if let e = error {
        print("获取告警记录失败, error: \(e)")
    }
})
接口说明
- (void)getUnlockRecordListWithOffset:(int)offset
                                limit:(int)limit
                              success:(nullable void(^)(NSArray<TuyaSmartBLELockRecordModel *> *records))success
                              failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| offset | 查询的页数 | 
| limit | 查询的条数 | 
| success | 成功回调,结果为记录列表 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock getUnlockRecordListWithOffset:0 limit:50 success:^(NSArray<TuyaSmartLockRecordModel *> * _Nonnull records) {
    NSLog(@"开锁记录: %@", records);
} failure:^(NSError *error) {
    NSLog(@"获取开锁记录失败,error: %@", error);
}];
Swift:
self.lock?.getUnlockRecordList(withOffset: 0, limit: 50, success: { (records) in
    print("开锁记录 \(records)")
}, failure: { (error) in
    if let e = error {
        print("获取开锁记录失败, error: \(e)")
    }
})
普通密码的时效性跟随成员的时效性,添加时需要门锁保持蓝牙连接。

接口说明
- (void)addPasswordForMemberWithMemberId:(NSString *)memberId
                                password:(NSString *)password
                              unlockName:(NSString *)unlockName
                           needHijacking:(BOOL)needHijacking
                                 success:(nullable TYSuccessString)success
                                 failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| memberId | 成员编号 ID | 
| password | 纯数字密码 | 
| unlockName | 密码名称 | 
| needHijacking | 是否需要设置为防劫持 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock addPasswordForMemberWithMemberId:@"00000074zg" password:@"774642" unlockName:@"密码 774642" needHijacking:YES success:^(NSString *result) {
        NSLog(@"创建密码成功");
} failure:^(NSError *error) {
        NSLog(@"创建密码失败 %@", error);
}];
Swift:
self.lock?.addPasswordForMember(withMemberId: "00000074zg", password: "774642", unlockName: "密码 774642", needHijacking: true, success: { (result) in
    print("创建密码成功")
}, failure: { (error) in
    if let e = error {
        print("创建密码失败, error: \(e)")
    }
})
接口说明
- (void)getPasswordListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockOpmodeModel *> *models))success
                           failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| success | 成功回调,普通密码列表 | 
| failure | 失败回调 | 
TuyaSmartBLELockOpmodeModel 数据模型
| 字段 | 类型 | 描述 | 
|---|---|---|
| opmode | NSString | 开锁方式 | 
| sourceAttribute | NSUInteger | 开锁方式来源 
 | 
| unlockName | NSString | 开锁方式名称 | 
| userName | NSString | 开锁用户名称 | 
| lockUserId | long long | 硬件内门锁成员 ID | 
| userId | NSString | 成员编号 ID | 
| opmodeValue | NSString | 开锁方式值,一般记录为门锁编号 | 
| opmodeId | NSString | 开锁方式的功能 ID | 
| unlockAttr | NSUInteger | 解锁方式属性, 1代表门锁劫持开锁 | 
示例代码
Objective-C:
[self.lock getPasswordListWithSuccess:^(NSArray<TuyaSmartBLELockOpmodeModel *> * _Nonnull models) {
    NSLog(@"获取密码列表 %@", models);
} failure:^(NSError *error) {
    NSLog(@"获取密码列表失败 %@", error);
}];
Swift:
self.lock?.getPasswordList(success: { (models) in
    print("获取密码列表 \(models)")
}, failure: { (error) in
    if let e = error {
        print("获取密码列表失败, error: \(e)")
    }
})
删除普通密码时,需要门锁保持蓝牙连接。

接口说明
- (void)removePasswordForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                       success:(TYSuccessHandler)success
                                       failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| opmodeModel | 开锁方式模型信息,来源自开锁方式列表 | 
示例代码
Objective-C:
[self.lock removePasswordForMemberWithOpmodeModel:model success:^{
    NSLog(@"删除开锁方式成功");
} failure:^(NSError *error) {
    NSLog(@"删除开锁方式失败 %@", error);
}];
Swift:
self.lock?.removePasswordForMember(with: model, success: {
    print("删除开锁方式成功")
}, failure: { (error) in
    if let e = error {
        print("删除开锁方式失败, error: \(e)")
    }
})
添加指纹密码需要与门锁频繁的交互,添加时需要门锁保持蓝牙连接。

接口说明
- (void)addFingerPrintForMemberWithMemberId:(NSString *)memberId
                                 unlockName:(NSString *)unlockName
                              needHijacking:(BOOL)needHijacking
                                    success:(TYSuccessString)success
                                    failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| memberId | 成员编号 ID | 
| unlockName | 密码名称 | 
| needHijacking | 是否需要设置为防劫持 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
// 设置代理,以接受和展示过程数据
self.lock.delegate = self;
[self.lock addFingerPrintForMemberWithMemberId:@"00000074zg" unlockName:@"添加的指纹" needHijacking:YES success:^(NSString *result) {
    NSLog(@"添加指纹成功");
} failure:^(NSError *error) {
    NSLog(@"添加指纹失败,error: %@", error);
}];
// TuyaSmartBLELockDeviceDelegate
- (void)device:(TuyaSmartBLELockDevice *)device didReceiveAddOpMessage:(TuyaSmartBLELockOpMessageModel *)opMessage {
    NSLog(@"收到新增开锁方式回调消息");
}
Swift:
self.lock?.delegate = self
self.lock?.addFingerPrintForMember(withMemberId: "", unlockName: "", needHijacking: true, success: { (result) in
    print("添加指纹成功")
}, failure: { (error) in
    if let e = error {
        print("添加指纹失败, error: \(e)")
    }
})
// TuyaSmartBLELockDeviceDelegate
extension ViewController :TuyaSmartBLELockDeviceDelegate {
    func device(_ device: TuyaSmartBLELockDevice, didReceiveAddOpMessage opMessage: TuyaSmartBLELockOpMessageModel) {
        print("收到新增开锁方式回调消息")
    }
}
接口说明
- (void)getFingerPrintListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockOpmodeModel *> *models))success
                              failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| success | 成功回调,指纹列表 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock getFingerPrintListWithSuccess:^(NSArray<TuyaSmartBLELockOpmodeModel *> * _Nonnull models) {
    NSLog(@"获取指纹列表 %@", models);
} failure:^(NSError *error) {
    NSLog(@"获取指纹列表失败 %@", error);
}];
Swift:
self.lock?.getFingerPrintList(success: { (models) in
    print("获取指纹列表 \(models)")
}, failure: { (error) in
    if let e = error {
        print("获取指纹列表失败, error: \(e)")
    }
})
删除指纹时,需要门锁保持蓝牙连接。

接口说明
- (void)removeFingerPrintForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                           success:(TYSuccessHandler)success
                                          failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| opmodeModel | 开锁方式模型信息,来源自开锁方式列表 | 
示例代码
Objective-C:
[self.lock removeFingerPrintForMemberWithOpmodeModel:model success:^{
    NSLog(@"删除开锁方式成功");
} failure:^(NSError *error) {
    NSLog(@"删除开锁方式失败 %@", error);
}];
Swift:
self.lock?.removeFingerPrintForMember(with: model, success: {
    print("删除开锁方式成功")
}, failure: { (error) in
    if let e = error {
        print("删除开锁方式失败, error: \(e)")
    }
})
添加卡片解锁时,需要门锁保持蓝牙连接。

接口说明
- (void)addCardForMemberWithMemberId:(NSString *)memberId
                          unlockName:(NSString *)unlockName
                       needHijacking:(BOOL)needHijacking
                             success:(TYSuccessString)success
                             failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| memberId | 成员编号 ID | 
| unlockName | 密码名称 | 
| needHijacking | 是否需要设置为防劫持 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock addCardForMemberWithMemberId:@"00000074zg" unlockName:@"卡片密码 1" needHijacking:YES success:^(NSString *result) {
        NSLog(@"创建卡片密码成功");
} failure:^(NSError *error) {
        NSLog(@"创建密码失败 %@", error);
}];
Swift:
self.lock?.addCardForMember(withMemberId: "00000074zg", unlockName: "卡片密码 1", needHijacking: true, success: { (result) in
    print("创建卡片密码成功")
}, failure: { (error) in
    if let e = error {
        print("创建密码失败, error: \(e)")
    }
})
接口说明
- (void)getCardListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockOpmodeModel *> *models))success
                       failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| success | 成功回调,卡片密码列表 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock getCardListWithSuccess:^(NSArray<TuyaSmartBLELockOpmodeModel *> * _Nonnull models) {
    NSLog(@"获取卡片密码列表 %@", models);
} failure:^(NSError *error) {
    NSLog(@"获取卡片密码列表失败 %@", error);
}];
Swift:
self.lock?.getCardList(success: { (models) in
    print("获取卡片密码列表 \(models)")
}, failure: { (error) in
    if let e = error {
        print("获取卡片密码列表失败, error: \(e)")
    }
})
删除卡片解锁方式时,需要门锁保持蓝牙连接。

接口说明
- (void)removeCardForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                   success:(TYSuccessHandler)success
                                   failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| opmodeModel | 开锁方式模型信息,来源自开锁方式列表 | 
示例代码
Objective-C:
[self.lock removeCardForMemberWithOpmodeModel:model success:^{
    NSLog(@"删除开锁方式成功");
} failure:^(NSError *error) {
    NSLog(@"删除开锁方式失败 %@", error);
}];
Swift:
self.lock?.removeCardForMember(with: model, success: {
    print("删除开锁方式成功")
}, failure: { (error) in
    if let e = error {
        print("删除开锁方式失败, error: \(e)")
    }
})
添加通用解锁方式时,需要门锁保持蓝牙连接。

接口说明
- (void)addUnlockOpmodeForMemberWithMemberId:(NSString *)memberId
                                     isAdmin:(BOOL)isAdmin
                                unlockDpCode:(NSString *)unlockDpCode
                                unlockOpType:(TYUnlockOpType)unlockOpType
                                  unlockName:(NSString *)unlockName
                               effectiveDate:(nullable NSDate *)effectiveDate
                                 invalidDate:(nullable NSDate *)invalidDate
                                       times:(int)times
                                  dataLength:(int)dataLength
                                 dataContent:(NSString *)dataContent
                                     timeout:(NSTimeInterval)timeout
                               needHijacking:(BOOL)needHijacking
                                     success:(nullable TYSuccessString)success
                                     failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| memberId | 成员编号 ID | 
| isAdmin | 是否是管理员 | 
| unlockDpCode | 解锁方式对应的功能标识,详细可查看 门锁功能列表,例如卡片解锁对应 unlock_card | 
| unlockOpType | 解锁方式,可查看 TYUnlockOpType枚举 | 
| unlockName | 解锁方式名称 | 
| effectiveDate | 生效时间 | 
| invalidDate | 失效时间 | 
| times | 解锁方式可用次数 | 
| dataLength | 数据长度,需要和数据内容长度保持一致 | 
| dataContent | 数据内容 | 
| timeout | 命令响应超时时间,如果是需要用户交互的,例如指纹,不用设置超时 | 
| needHijacking | 是否需要设置防劫持 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock addUnlockOpmodeForMemberWithMemberId:@"00000074zg"
                                        isAdmin:NO
                                    unlockDpCode:@"unlock_password"
                                    unlockOpType:TYUnlockOpTypePassword
                                      unlockName:@"密码 774641"
                                   effectiveDate:nil
                                     invalidDate:nil
                                           times:10
                                      dataLength:6
                                     dataContent:@"774641"
                                         timeout:6
                                   needHijacking:YES
                                         success:^(NSString *result) {
    NSLog(@"添加成功");
} failure:^(NSError *error) {
    NSLog(@"添加失败 %@", error);
}];
Swift:
self.lock?.addUnlockOpmodeForMember(withMemberId: "00000074zg", isAdmin: false, unlockDpCode: "unlock_password", unlockOpType: TYUnlockOpTypePassword, unlockName: "密码 774641", effectiveDate: nil, invalidDate: nil, times: 10, dataLength: 6, dataContent: "774641", timeout: 5, needHijacking: true, success: { (result) in
        print("添加成功")
}, failure: { (error) in
    if let e = error {
        print("添加失败, error: \(e)")
    }
})
修改、更新通用的解锁方式时,需要门锁保持蓝牙连接。

接口说明
- (void)modifyUnlockOpmodeForMemberWithMemberId:(NSString *)memberId
                                       opmodeId:(NSString *)opmodeId
                                        isAdmin:(BOOL)isAdmin
                                     firmwareId:(int)firmwareId
                                   unlockDpCode:(NSString *)unlockDpCode
                                   unlockOpType:(TYUnlockOpType)unlockOpType
                                     unlockName:(NSString *)unlockName
                                  effectiveDate:(nullable NSDate *)effectiveDate
                                    invalidDate:(nullable NSDate *)invalidDate
                                          times:(int)times
                                     dataLength:(int)dataLength
                                    dataContent:(NSString *)dataContent
                                        timeout:(NSTimeInterval)timeout
                                  needHijacking:(BOOL)needHijacking
                                        success:(nullable TYSuccessBOOL)success
                                        failure:(nullable TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| memberId | 成员编号 ID | 
| opmodeId | 开锁方式 ID,来源获取的开锁方式列表 | 
| isAdmin | 是否是管理员 | 
| firmwareId | 硬件 ID | 
| unlockDpCode | 解锁方式对应的功能标识,详细可查看 门锁功能列表,例如卡片解锁对应 unlock_card | 
| unlockOpType | 解锁方式,可查看 TYUnlockOpType枚举 | 
| unlockName | 解锁方式名称 | 
| effectiveDate | 生效时间 | 
| invalidDate | 失效时间 | 
| times | 解锁方式可用次数 | 
| dataLength | 数据长度,需要和数据内容长度保持一致 | 
| dataContent | 数据内容 | 
| timeout | 命令响应超时时间,如果是需要用户交互的,例如指纹,不用设置超时 | 
| needHijacking | 是否需要设置防劫持 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock modifyUnlockOpmodeForMemberWithMemberId:@"00000074zg"
                                            opmodeId:@"232323"
                                            isAdmin:NO
                                        firmwareId:15 //来源自开锁方式数据中的 opmodevalue
                                        unlockDpCode:@"unlock_password"
                                        unlockOpType:TYUnlockOpTypePassword
                                        unlockName:@"密码 774641"
                                        effectiveDate:nil
                                        invalidDate:nil
                                                times:10
                                        dataLength:6
                                        dataContent:@"774641"
                                            timeout:6
                                        needHijacking:YES
                                            success:^(NSString *result) {
    NSLog(@"更新成功");
} failure:^(NSError *error) {
    NSLog(@"更新失败 %@", error);
}];
Swift:
self.lock?.modifyUnlockOpmodeForMember(withMemberId: "00000074zg", opmodeId: "232323", isAdmin: false, firmwareId: 15, unlockDpCode: "unlock_password", unlockOpType: TYUnlockOpTypePassword, unlockName: "密码 774641", effectiveDate: nil, invalidDate: nil, times: 10, dataLength: 6, dataContent: "774641", timeout: 5, needHijacking: true, success: { (result) in
	print("更新成功")
}, failure: { (error) in
	if let e = error {
		print("更新失败, error: \(e)")
	}
})
接口说明
- (void)removeUnlockOpmodeForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                           isAdmin:(BOOL)isAdmin
                                      unlockDpCode:(NSString *)unlockDpCode
                                      unlockOpType:(TYUnlockOpType)unlockOpType
                                           timeout:(NSTimeInterval)timeout
                                           success:(TYSuccessHandler)success
                                           failure:(TYFailureError)failure;
参数说明
| 参数 | 说明 | 
|---|---|
| opmodeModel | 开锁方式模型 | 
| isAdmin | 是否是管理员 | 
| unlockDpCode | 解锁方式对应的功能标识,详细可查看 门锁功能列表,例如卡片解锁对应 unlock_card | 
| unlockOpType | 解锁方式,可查看 TYUnlockOpType枚举 | 
| timeout | 命令响应超时时间,如果是需要用户交互的,例如指纹,不用设置超时 | 
| success | 成功回调 | 
| failure | 失败回调 | 
示例代码
Objective-C:
[self.lock removeUnlockOpmodeForMemberWithOpmodeModel:model
                                              isAdmin:NO
                                         unlockDpCode:@"unlock_password"
                                         unlockOpType:TYUnlockOpTypePassword
                                              timeout:10
                                              success:^{
NSLog(@"删除成功");
} failure:^(NSError *error) {
NSLog(@"删除失败 %@", error);
}]
Swift:
self.lock?.removeUnlockOpmodeForMember(with: model, isAdmin: false, unlockDpCode: "unlock_password", unlockOpType: TYUnlockOpTypePassword, timeout: 10, success: {
	print("删除成功")
}, failure: { (error) in
	if let e = error {
		print("删除失败, error: \(e)")
	}
})
| 功能名称 | 功能标识符(dpCode) | 
|---|---|
| 添加开门方式 | unlock_method_create | 
| 删除开门方式 | unlock_method_delete | 
| 修改开门方式 | unlock_method_modify | 
| 冻结开门方式 | unlock_method_freeze | 
| 解冻开门方式 | unlock_method_enable | 
| 蓝牙解锁 | bluetooth_unlock | 
| 蓝牙解锁反馈 | bluetooth_unlock_fb | 
| 剩余电量 | residual_electricity | 
| 电量状态 | battery_state | 
| 童锁状态 | child_lock | 
| 上提反锁 | anti_lock_outside | 
| 指纹解锁 | unlock_fingerprint | 
| 普通密码解锁 | unlock_password | 
| 动态密码解锁 | unlock_dynamic | 
| 卡片解锁 | unlock_card | 
| 钥匙解锁 | unlock_key | 
| 开关门事件 | open_close | 
| 从门内侧打开门锁 | open_inside | 
| 蓝牙解锁记录 | unlock_ble | 
| 门被打开 | door_opened | 
| 告警 | alarm_lock | 
| 劫持报警 | hijack | 
| 门铃呼叫 | doorbell | 
| 短信通知 | message | 
| 门铃选择 | doorbell_song | 
| 门铃音量 | doorbell_volume | 
| 门锁语言切换 | language | 
| 显示屏欢迎词管理 | welcome_words | 
| 按键音量 | key_tone | 
| 门锁本地导航音量 | beep_volume | 
| 反锁状态 | reverse_lock | 
| 自动落锁开关 | automatic_lock | 
| 单一解锁与组合解锁切换 | unlock_switch | 
| 同步成员开门方式 | synch_member | 
| 自动落锁延时设置 | auto_lock_time | 
| 定时自动落锁 | auto_lock_timer | 
| 指纹录入次数 | finger_input_times | 
| 人脸识别解锁 | unlock_face | 
| 开合状态 | closed_opened | 
| 虹膜解锁 | unlock_eye | 
| 掌纹解锁 | unlock_hand | 
| 指静脉解锁 | unlock_finger_vein | 
| 硬件时钟 RTC | rtc_lock | 
| 自动落锁倒计时上报 | auto_lock_countdown | 
| 手动落锁 | manual_lock | 
| 落锁状态 | lock_motor_state | 
| 锁帖电机转动方向 | lock_motor_direction | 
| 冻结用户 | unlock_user_freeze | 
| 解冻用户 | unlock_user_enable | 
| 蓝牙锁临时密码添加 | temporary password_creat | 
| 蓝牙锁临时密码删除 | temporary password_delete | 
| 蓝牙锁临时密码修改 | temporary password_modify | 
| 同步开门方式(数据量大) | synch_method | 
| 临时密码解锁 | unlock_temporary | 
| 电机扭力 | motor_torque | 
| 组合开锁记录 | unlock_double | 
| 离家布防开关 | arming_mode | 
| 配置新免密远程解锁 | remote_no_pd_setkey | 
| 新免密远程开门(带密钥) | remote_no_dp_key | 
| 远程手机解锁上报 | unlock_phone_remote | 
| 远程语音解锁上报 | unlock_voice_remote | 
| 离线密码 T0 时间下发 | password_offline_time | 
| 单条离线密码清空上报 | unlock_offline_clear_single | 
| 离线密码清空上报 | unlock_offline_clear | 
| 离线密码解锁上报 | unlock_offline_pd | 
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈