Last Updated on : 2023-06-12 07:51:08download
| Class name | Description | 
|---|---|
| TuyaSmartBLELockDevice | Bluetooth lock operation class, inherited from TuyaSmartDevice | 
| TuyaSmartBLELockDeviceDelegate | Bluetooth lock protocol delegate, extended from TuyaSmartDeviceDelegate | 
| Term | Description | 
|---|---|
| Locks that support duress alarms | The duress alarm feature allows users to enroll a password or fingerprint as a duress code. If they are coerced by hostile persons, unlocking with the duress code can trigger alarms to be sent to a list of contacts. | 
| Lock members | Lock members are classified into home members and non-home members. 
 | 
| lockUserId | A lockUserIdis a firmware member ID that the cloud assigns to a lock when you create a lock member. EachlockUserIdindicates the member ID that is recorded in the firmware. | 
| userId | A userIdis the ID that the cloud assigns to a lock member when you create the member. EachuserIdis a unique ID of each user and is recorded in a database. | 
| dpCode | An identifier of a data point (DP) for a device. Each data point is assigned a name and a dpCode. For more information, see the List of Bluetooth lock DPs. | 
This section describes the operations regarding non-home members.
API description
- (void)getMemberListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockMemberModel *> *members))success
                         failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| success | The success callback. A list of members is returned. | 
| failure | The failure callback. | 
Data model of TuyaSmartBLELockMemberModel
| Field | Type | Description | 
|---|---|---|
| userId | NSString | The member ID. | 
| userContact | NSString | The contact method. | 
| avatarUrl | NSString | The URL of the avatar. | 
| nickName | NSString | The name of the member. | 
| userTimeSet | NSString | The validity data of the member. | 
| phase | NSUInteger | The freezing status. Valid values: 
 | 
| status | NSUInteger | The status of the user. | 
| lockUserId | int | The user ID. | 
| userType | NSUInteger | The type of user. Valid values: 
 | 
| supportOpenType | NSArray | The supported unlocking methods. | 
| shareUser | NSString | The user account that receives the sharing invitation. | 
| productAttribute | NSUInteger | The attribute of the lock. | 
Example
ObjC:
[self.lock getMemberListWithSuccess:^(NSArray<TuyaSmartBLELockMemberModel *> * _Nonnull list) {
    NSLog(@"Member list %@", list);
} failure:^(NSError *error) {
    NSLog(@"Failed to get a list of members, error: %@", error);
}];
Swift:
self.lock?.getMemberList(success: { (list) in
    print("Member list \(list)")
}, failure: { (error) in
    if let e = error {
        print("Failed to get a list of members, error: \(e)")
    }
})
Creates a non-home member to be associated with an unlocking method in later operations.

API description
- (void)addMemberWithUserName:(NSString *)userName
                  allowUnlock:(BOOL)allowUnlock
                     timeType:(TYMemberTimeType)timeType
                effectiveDate:(NSDate *)effectiveDate
                  invalidDate:(NSDate *)invalidDate
                      success:(nullable TYSuccessBOOL)success
                      failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| userName | The name of the member. | 
| allowUnlock | Specifies whether the member can unlock over Bluetooth. | 
| timeType | The validity period of the member. Valid values: 
 | 
| effectiveDate | The time when the unlocking access starts. | 
| invalidDate | The time when the unlocking access ends. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock addMemberWithUserName:#<Member name># allowUnlock:YES timeType:TYMemberTimeTypePhase effectiveDate:[NSDate date] invalidDate:[[NSDate date] dateByAddingTimeInterval:60 * 60 * 8] success:^(BOOL result) {
    NSLog(@"Member created successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to create the member, error: %@", error);
}];
Swift:
self.lock?.addMember(withUserName: "name", allowUnlock: true, timeType: .phase, effectiveDate: Date(), invalidDate: Date().addingTimeInterval(60 * 60 * 8), success: { (result) in
    print("Member created successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to create the member, error: \(e)")
    }
})
Modifies a lock member. This feature requires communication between your app and a Bluetooth lock. Your app must be connected to the lock over Bluetooth during the operation.

API description
- (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;
Parameters
| Parameter | Description | 
|---|---|
| userName | The name of the member. | 
| memberId | The member ID. | 
| allowUnlock | Specifies whether the member can unlock over Bluetooth. | 
| timeType | The validity period of the member’s unlocking permission. Valid values: 
 | 
| effectiveDate | The time when the unlocking access starts. | 
| invalidDate | The time when the unlocking access ends. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[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(@"Member modified successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to create the member, 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("Member modified successfully.")
    }, failure: { (error) in
        if let e = error {
            print("Failed to modify member information, error: \(e)")
        }
    })
You can call this operation to delete a lock member. This feature requires communication between your app and a Bluetooth lock. Your app must be connected to the lock over Bluetooth during the operation. After a lock member is deleted, all unlocking methods and passwords that are associated with the member are deleted.

API description
- (void)removeMemberWithMemberId:(NSString *)memberId
                         success:(nullable TYSuccessBOOL)success
                         failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| memberId | The member ID. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock removeMemberWithMemberId:@"000000747d" success:^(BOOL result) {
    NSLog(@"Member deleted successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to delete the member, error: %@", error);
}];
Swift:
self.lock?.removeMember(withMemberId: "", success: { (result) in
    print("Member deleted successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to delete the member, error: \(e)")
    }
})
To use certain features of a Bluetooth lock, you must enable the Bluetooth feature on your app. The SDK can be used to enable an automatic connection with the lock over Bluetooth. The following API methods can be called to create a connection and query the connection status.
API description
/// Creates a Bluetooth connection in case the connection attempt failed or the connection is interrupted.
- (void)autoConnect;
/// Checks whether a Bluetooth connection is created between the lock and the mobile phone. If `NO` is returned, you can call `autoConnect` to try again.
- (BOOL)isBLEConnected;
Returns a dynamic password.
API description
- (void)getLockDynamicPasswordWithSuccess:(nullable TYSuccessString)success
                                  failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| success | The success callback. The dynamic password is returned. | 
| failure | The failure callback. | 
Example
ObjC:
TuyaSmartBLELockDevice *lock = [TuyaSmartBLELockDevice deviceWithDeviceId:@"your_lock_device_id"];
[lock getLockDynamicPasswordWithSuccess:^(NSString *result) {
    NSLog(@"Result of querying a dynamic password %@", result);
} failure:^(NSError *error) {
    NSLog(@"error %@", error);
}];
Swift:
let lockDevice = TuyaSmartBLELockDevice(deviceId: "your_lock_device_id")
lockDevice?.getLockDynamicPassword(success: { (pwd) in
    print("Result of querying a dynamic password \(pwd)")
}, failure: { (error) in
    if let e = error {
        print("error \(e)")
    }
})

API description
- (void)unlockWithStatus:(BOOL)status
                 success:(nullable TYSuccessHandler)success
                 failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| status | The unlocking and locking status. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
TuyaSmartBLELockDevice *lock = [TuyaSmartBLELockDevice deviceWithDeviceId:@"your_lock_device_id"];
BOOL status = YES;
[lock unlockWithStatus:status success:^{
    NSLog(@"Unlocked successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to unlock, error %@", error);
}];
Swift:
let lockDevice = TuyaSmartBLELockDevice(deviceId: "your_lock_device_id")
self.lock?.unlock(withStatus: status, success: {
    print("Unlocked successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to unlock, error: \(e)")
    }
})

API description
- (void)manualLockWithStatus:(BOOL)status
                     success:(TYSuccessHandler)success
                     failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| status | The unlocking or locking status. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
TuyaSmartBLELockDevice *lock = [TuyaSmartBLELockDevice deviceWithDeviceId:@"your_lock_device_id"];
BOOL status = YES;
[lock manualLockWithStatus:status success:^{
    NSLog(@"Locked successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to lock, error %@", error);
}];
Swift:
let lockDevice = TuyaSmartBLELockDevice(deviceId: "your_lock_device_id")
self.lock?.manualLock(withStatus: status, success: {
    print("Locked successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to lock, error: \(e)")
    }
})
API description
- (void)getAlarmRecordListWithOffset:(int)offset
                               limit:(int)limit
                             success:(nullable void(^)(NSArray<TuyaSmartLockRecordModel *> *records))success
                             failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| offset | The page number starting which entries are returned. | 
| limit | The total number of returned entries in each call. | 
| success | The success callback. A list of alert records is returned. | 
| failure | The failure callback. | 
Data model of TuyaSmartLockRecordModel
| Field | Type | Description | 
|---|---|---|
| userId | NSString | The member ID. | 
| userName | NSString | The nickname of the user. | 
| time | NSTimeInterval | The 13-bit timestamp when the record was generated. | 
| devId | NSString | The device ID. | 
| dpData | NSDictionary | The DP data. | 
| tags | NSInteger | The flag of the record. Valid values: 
 | 
| dpsArray | NSArray<NSDictionary *> | The array of device DPs. | 
Example
ObjC:
[self.lock getAlarmRecordListWithOffset:0 limit:50 success:^(NSArray<TuyaSmartLockRecordModel *> * _Nonnull records) {
    NSLog(@"Alert records: %@", records);
} failure:^(NSError *error) {
    NSLog(@"Failed to get alert records, error: %@", error);
}];
Swift:
self.lock?.getAlarmRecordList(withOffset: 0, limit: 50, success: { (records) in
    print("Alert records \(records)")
}, failure: { (error) in
    if let e = error {
        print("Failed to query alert records, error: \(e)")
    }
})
API description
- (void)getUnlockRecordListWithOffset:(int)offset
                                limit:(int)limit
                              success:(nullable void(^)(NSArray<TuyaSmartBLELockRecordModel *> *records))success
                              failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| offset | The page number starting from which entries are returned. | 
| limit | The total number of returned entries in each call. | 
| success | The success callback. A list of alert records is returned. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock getUnlockRecordListWithOffset:0 limit:50 success:^(NSArray<TuyaSmartLockRecordModel *> * _Nonnull records) {
    NSLog(@"Unlocking records: %@", records);
} failure:^(NSError *error) {
    NSLog(@"Failed to query unlocking records, error: %@", error);
}];
Swift:
self.lock?.getUnlockRecordList(withOffset: 0, limit: 50, success: { (records) in
    print("Unlocking records \(records)")
}, failure: { (error) in
    if let e = error {
        print("Failed to query unlocking records, error: \(e)")
    }
})
Adds a normal password. Its validity period follows the member’s validity. Your app must be connected to the lock over Bluetooth during the operation.

API description
- (void)addPasswordForMemberWithMemberId:(NSString *)memberId
                                password:(NSString *)password
                              unlockName:(NSString *)unlockName
                           needHijacking:(BOOL)needHijacking
                                 success:(nullable TYSuccessString)success
                                 failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| memberId | The member ID. | 
| password | The numeric password. | 
| unlockName | The name of the password. | 
| needHijacking | Specifies whether to enable duress alarms. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock addPasswordForMemberWithMemberId:@"00000074zg" password:@"774642" unlockName:@"Password 774642" needHijacking:YES success:^(NSString *result) {
        NSLog(@"Password created successfully.");
} failure:^(NSError *error) {
        NSLog(@"Failed to create the password. %@", error);
}];
Swift:
self.lock?.addPasswordForMember(withMemberId: "00000074zg", password: "774642", unlockName: "Password 774642", needHijacking: true, success: { (result) in
    print("Password created successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to create the password, error: \(e)")
    }
})
API description
- (void)getPasswordListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockOpmodeModel *> *models))success
                           failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| success | The success callback. A list of normal passwords is returned. | 
| failure | The failure callback. | 
Data model of TuyaSmartBLELockOpmodeModel
| Field | Type | Description | 
|---|---|---|
| opmode | NSString | The unlocking method. | 
| sourceAttribute | NSUInteger | The source of the unlocking method. 
 | 
| unlockName | NSString | The name of the unlocking method. | 
| userName | NSString | The name of the unlocking user. | 
| lockUserId | long long | The lock user ID. | 
| userId | NSString | The member ID. | 
| opmodeValue | NSString | The value of the unlocking method, generally recorded as the lock ID. | 
| opmodeId | NSString | The DP ID of the unlocking method. | 
| unlockAttr | NSUInteger | The attribute of the unlocking method. 1indicates a duress alarm. | 
Example
ObjC:
[self.lock getPasswordListWithSuccess:^(NSArray<TuyaSmartBLELockOpmodeModel *> * _Nonnull models) {
    NSLog(@"Password list returned successfully. %@", models);
} failure:^(NSError *error) {
    NSLog(@"Failed to return the password list. %@", error);
}];
Swift:
self.lock?.getPasswordList(success: { (models) in
    print("Password list returned successfully. \(models)")
}, failure: { (error) in
    if let e = error {
        print("Failed to return the password list, error: \(e)")
    }
})
Deletes a normal password. Your application must be connected to the lock over Bluetooth during the operation.

API description
- (void)removePasswordForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                       success:(TYSuccessHandler)success
                                       failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| opmodeModel | The model of the unlocking method. You can get the model from the list of unlocking methods. | 
Example
ObjC:
[self.lock removePasswordForMemberWithOpmodeModel:model success:^{
    NSLog(@"Unlocking method deleted successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to delete the unlocking method. %@", error);
}];
Swift:
self.lock?.removePasswordForMember(with: model, success: {
    print("Unlocking method deleted successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to delete the unlocking method, error: \(e)")
    }
})
Adds a fingerprint password. This feature requires frequent interaction with the lock. Your app must be connected to the lock over Bluetooth during the operation.

API description
- (void)addFingerPrintForMemberWithMemberId:(NSString *)memberId
                                 unlockName:(NSString *)unlockName
                              needHijacking:(BOOL)needHijacking
                                    success:(TYSuccessString)success
                                    failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| memberId | The member ID. | 
| unlockName | The name of the password. | 
| needHijacking | Specifies whether to enable duress alarms. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
// Sets a delegate to receive and display process data.
self.lock.delegate = self;
[self.lock addFingerPrintForMemberWithMemberId:@"00000074zg" unlockName:@"Added fingerprint" needHijacking:YES success:^(NSString *result) {
    NSLog(@"Fingerprint added successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to add a fingerprint, error: %@", error);
}];
// TuyaSmartBLELockDeviceDelegate
- (void)device:(TuyaSmartBLELockDevice *)device didReceiveAddOpMessage:(TuyaSmartBLELockOpMessageModel *)opMessage {
    NSLog(@"Callback executed after the new unlocking method is added.");
}
Swift:
self.lock?.delegate = self
self.lock?.addFingerPrintForMember(withMemberId: "", unlockName: "", needHijacking: true, success: { (result) in
    print("Fingerprint added successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to add the fingerprint, error: \(e)")
    }
})
// TuyaSmartBLELockDeviceDelegate
extension ViewController :TuyaSmartBLELockDeviceDelegate {
    func device(_ device: TuyaSmartBLELockDevice, didReceiveAddOpMessage opMessage: TuyaSmartBLELockOpMessageModel) {
        print("Callback executed after the new unlocking method is added.")
    }
}
API description
- (void)getFingerPrintListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockOpmodeModel *> *models))success
                              failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| success | The success callback. A list of fingerprint data is returned. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock getFingerPrintListWithSuccess:^(NSArray<TuyaSmartBLELockOpmodeModel *> * _Nonnull models) {
    NSLog(@"Fingerprint list returned successfully. %@", models);
} failure:^(NSError *error) {
    NSLog(@"Failed to return the fingerprint list. %@", error);
}];
Swift:
self.lock?.getFingerPrintList(success: { (models) in
    print("Fingerprint list returned successfully. \(models)")
}, failure: { (error) in
    if let e = error {
        print("Failed to return the fingerprint list. error: \(e)")
    }
})
Deletes a fingerprint password. Your application must be connected to the lock over Bluetooth during the operation.

API description
- (void)removeFingerPrintForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                           success:(TYSuccessHandler)success
                                          failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| opmodeModel | The model of the unlocking method. You can get the model from the list of unlocking methods. | 
Example
ObjC:
[self.lock removeFingerPrintForMemberWithOpmodeModel:model success:^{
    NSLog(@"Unlocking method deleted successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to delete the unlocking method. %@", error);
}];
Swift:
self.lock?.removeFingerPrintForMember(with: model, success: {
    print("Unlocking method deleted successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to delete the unlocking method, error: \(e)")
    }
})
Adds a card unlocking method. Your application must be connected to the lock over Bluetooth during the operation.

API description
- (void)addCardForMemberWithMemberId:(NSString *)memberId
                          unlockName:(NSString *)unlockName
                       needHijacking:(BOOL)needHijacking
                             success:(TYSuccessString)success
                             failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| memberId | The member ID. | 
| unlockName | The name of the password. | 
| needHijacking | Specifies whether to enable duress alarms. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock addCardForMemberWithMemberId:@"00000074zg" unlockName:@"Card password 1" needHijacking:YES success:^(NSString *result) {
        NSLog(@"Card password created successfully.");
} failure:^(NSError *error) {
        NSLog(@"Failed to create the password. %@", error);
}];
Swift:
self.lock?.addCardForMember(withMemberId: "00000074zg", unlockName: "Card password 1", needHijacking: true, success: { (result) in
    print("Card password created successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to create the password, error: \(e)")
    }
})
API description
- (void)getCardListWithSuccess:(nullable void(^)(NSArray<TuyaSmartBLELockOpmodeModel *> *models))success
                       failure:(nullable TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| success | The success callback. A list of card passwords is returned. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock getCardListWithSuccess:^(NSArray<TuyaSmartBLELockOpmodeModel *> * _Nonnull models) {
    NSLog(@"Card password list returned successfully. %@", models);
} failure:^(NSError *error) {
    NSLog(@"Failed to return the card password list. %@", error);
}];
Swift:
self.lock?.getCardList(success: { (models) in
    print("Card password list returned successfully. \(models)")
}, failure: { (error) in
    if let e = error {
        print("Failed to return the card password list, error: \(e)")
    }
})
Deletes a card unlocking method. Your application must be connected to the lock over Bluetooth during the operation.

API description
- (void)removeCardForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                   success:(TYSuccessHandler)success
                                   failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| opmodeModel | The model of the unlocking method. You can get the model from the list of unlocking methods. | 
Example
ObjC:
[self.lock removeCardForMemberWithOpmodeModel:model success:^{
    NSLog(@"Unlocking method deleted successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to delete the unlocking method. %@", error);
}];
Swift:
self.lock?.removeCardForMember(with: model, success: {
    print("Unlocking method deleted successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to delete the unlocking method, error: \(e)")
    }
})
Adds a generic unlocking method. Your application must be connected to the lock over Bluetooth during the operation.

API description
- (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;
Parameters
| Parameter | Description | 
|---|---|
| memberId | The member ID. | 
| isAdmin | Specifies whether the user is an administrator. | 
| unlockDpCode | The DP identifier of the unlocking method. For more information, see List of lock DPs. For example, unlock_cardrepresents the card unlocking method. | 
| unlockOpType | The unlocking method. For more information, see the enum values of TYUnlockOpType. | 
| unlockName | The name of the unlocking method. | 
| effectiveDate | The time when the unlocking method takes effect. | 
| invalidDate | The time when the unlocking method expires. | 
| times | The maximum number of times the unlocking method can be used. | 
| dataLength | The data length. It must be the same as the length of dataContent. | 
| dataContent | The data content. | 
| timeout | The timeout value for a response. During the interaction with users, such as fingerprint operations, this parameter is not required. | 
| needHijacking | Specifies whether to enable duress alarms. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock addUnlockOpmodeForMemberWithMemberId:@"00000074zg"
                                        isAdmin:NO
                                    unlockDpCode:@"unlock_password"
                                    unlockOpType:TYUnlockOpTypePassword
                                      unlockName:@"Password 774641"
                                   effectiveDate:nil
                                     invalidDate:nil
                                           times:10
                                      dataLength:6
                                     dataContent:@"774641"
                                         timeout:6
                                   needHijacking:YES
                                         success:^(NSString *result) {
    NSLog(@"Added successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to add. %@", error);
}];
Swift:
self.lock?.addUnlockOpmodeForMember(withMemberId: "00000074zg", isAdmin: false, unlockDpCode: "unlock_password", unlockOpType: TYUnlockOpTypePassword, unlockName: "Password 774641", effectiveDate: nil, invalidDate: nil, times: 10, dataLength: 6, dataContent: "774641", timeout: 5, needHijacking: true, success: { (result) in
        print("Added successfully.")
}, failure: { (error) in
    if let e = error {
        print("Failed to add, error: \(e)")
    }
})
Modifies a generic unlocking method. Your application must be connected to the lock over Bluetooth during the operation.

API description
- (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;
Parameters
| Parameter | Description | 
|---|---|
| memberId | The member ID. | 
| opmodeId | The unlocking method ID. You can get the value from the list of unlocking methods. | 
| isAdmin | Specifies whether the user is an administrator. | 
| firmwareId | The hardware ID. | 
| unlockDpCode | The DP identifier of the unlocking method. For more information, see List of lock DPs. For example, unlock_cardrepresents the card unlocking method. | 
| unlockOpType | The unlocking method. For more information, see the enum values of TYUnlockOpType. | 
| unlockName | The name of the unlocking method. | 
| effectiveDate | The time when the unlocking method takes effect. | 
| invalidDate | The time when the unlocking method expires. | 
| times | The maximum number of times the unlocking method can be used. | 
| dataLength | The data length. It must be the same as the length of dataContent. | 
| dataContent | The data content. | 
| timeout | The timeout value for a response. During the interaction with users, such as fingerprint operations, this parameter is not required. | 
| needHijacking | Specifies whether to enable duress alarms. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock modifyUnlockOpmodeForMemberWithMemberId:@"00000074zg"
                                            opmodeId:@"232323"
                                            isAdmin:NO
                                        firmwareId:15 // The value can be obtained from `opmodevalue` of the unlocking method.
                                        unlockDpCode:@"unlock_password"
                                        unlockOpType:TYUnlockOpTypePassword
                                        unlockName:@"Password 774641"
                                        effectiveDate:nil
                                        invalidDate:nil
                                                times:10
                                        dataLength:6
                                        dataContent:@"774641"
                                            timeout:6
                                        needHijacking:YES
                                            success:^(NSString *result) {
    NSLog(@"Updated successfully.");
} failure:^(NSError *error) {
    NSLog(@"Failed to update. %@", error);
}];
Swift:
self.lock?.modifyUnlockOpmodeForMember(withMemberId: "00000074zg", opmodeId: "232323", isAdmin: false, firmwareId: 15, unlockDpCode: "unlock_password", unlockOpType: TYUnlockOpTypePassword, unlockName: "Password 774641", effectiveDate: nil, invalidDate: nil, times: 10, dataLength: 6, dataContent: "774641", timeout: 5, needHijacking: true, success: { (result) in
	print("Updated successfully.")
}, failure: { (error) in
	if let e = error {
		print("Failed to update, error: \(e)")
	}
})
API description
- (void)removeUnlockOpmodeForMemberWithOpmodeModel:(TuyaSmartBLELockOpmodeModel *)opmodeModel
                                           isAdmin:(BOOL)isAdmin
                                      unlockDpCode:(NSString *)unlockDpCode
                                      unlockOpType:(TYUnlockOpType)unlockOpType
                                           timeout:(NSTimeInterval)timeout
                                           success:(TYSuccessHandler)success
                                           failure:(TYFailureError)failure;
Parameters
| Parameter | Description | 
|---|---|
| opmodeModel | The model of the unlocking method. | 
| isAdmin | Specifies whether the user is an administrator. | 
| unlockDpCode | The DP identifier of the unlocking method. For more information, see List of lock DPs. For example, unlock_cardrepresents the card unlocking method. | 
| unlockOpType | The unlocking method. For more information, see the enum values of TYUnlockOpType. | 
| timeout | The timeout value for a response. During the interaction with users, such as fingerprint operations, this parameter is not required. | 
| success | The success callback. | 
| failure | The failure callback. | 
Example
ObjC:
[self.lock removeUnlockOpmodeForMemberWithOpmodeModel:model
                                              isAdmin:NO
                                         unlockDpCode:@"unlock_password"
                                         unlockOpType:TYUnlockOpTypePassword
                                              timeout:10
                                              success:^{
NSLog(@"Deleted successfully.");
} failure:^(NSError *error) {
NSLog(@"Failed to delete. %@", error);
}]
Swift:
self.lock?.removeUnlockOpmodeForMember(with: model, isAdmin: false, unlockDpCode: "unlock_password", unlockOpType: TYUnlockOpTypePassword, timeout: 10, success: {
	print("Deleted successfully.")
}, failure: { (error) in
	if let e = error {
		print("Failed to delete. error: \(e)")
	}
})
| DP name | DP identifier (dpCode) | 
|---|---|
| Add an unlocking method | unlock_method_create | 
| Delete an unlocking method | unlock_method_delete | 
| Modify an unlocking method | unlock_method_modify | 
| Disable an unlocking method | unlock_method_freeze | 
| Enable an unlocking method | unlock_method_enable | 
| Unlock over Bluetooth | bluetooth_unlock | 
| Get feedback on Bluetooth-based unlocking | bluetooth_unlock_fb | 
| Remaining battery capacity | residual_electricity | 
| Battery status | battery_state | 
| Child lock status | child_lock | 
| Double lock by lifting up | anti_lock_outside | 
| Unlock with a fingerprint | unlock_fingerprint | 
| Unlock with a normal password | unlock_password | 
| Unlock with a dynamic password | unlock_dynamic | 
| Unlock with a card | unlock_card | 
| Unlock with a mechanical key | unlock_key | 
| Door opening and closing events | open_close | 
| Unlock from the inside of the door | open_inside | 
| Records of Bluetooth-based unlocking | unlock_ble | 
| Door opened | door_opened | 
| Alerts | alarm_lock | 
| Duress alarms | hijack | 
| Doorbell call | doorbell | 
| SMS notification | message | 
| Chime sounds | doorbell_song | 
| Sound level of the chime | doorbell_volume | 
| Language switching | language | 
| Manage welcome messages on the display screen | welcome_words | 
| Volume on keypress | key_tone | 
| Local voice guidance volume | beep_volume | 
| Double locking status | reverse_lock | 
| Switch of automatic latch | automatic_lock | 
| Switch between single unlocking and combination unlocking | unlock_switch | 
| Synchronize unlocking methods among members | synch_member | 
| Set the latency of automatic latch | auto_lock_time | 
| Timed automatic locking | auto_lock_timer | 
| Number of fingerprint enrollments | finger_input_times | 
| Unlock with biometric recognition | unlock_face | 
| Open and closed status of the door | closed_opened | 
| Unlock with irises | unlock_eye | 
| Unlock with palm prints | unlock_hand | 
| Unlock with finger veins | unlock_finger_vein | 
| Hardware RTC | rtc_lock | 
| Report of countdown for automatic locking | auto_lock_countdown | 
| Manual locking | manual_lock | 
| Locking status | lock_motor_state | 
| Rotation direction of the motor on a smart stick lock | lock_motor_direction | 
| Disable users | unlock_user_freeze | 
| Enable users | unlock_user_enable | 
| Add a temporary password to a Bluetooth lock | temporary password_creat | 
| Delete a temporary password from a Bluetooth lock | temporary password_delete | 
| Modify a temporary password of a Bluetooth lock | temporary password_modify | 
| Synchronize unlocking methods (large datasets) | synch_method | 
| Unlock with a temporary password | unlock_temporary | 
| Motor torque | motor_torque | 
| Records of combination unlocking | unlock_double | 
| Switch of the arm away mode | arming_mode | 
| Configure password-free remote unlocking | remote_no_pd_setkey | 
| Password-free remote unlocking with keys | remote_no_dp_key | 
| Remote unlocking with mobile phones | unlock_phone_remote | 
| Remote unlocking with voice | unlock_voice_remote | 
| Send the offline password T0 time | password_offline_time | 
| Report the clearing of a single offline password | unlock_offline_clear_single | 
| Report the clearing of offline passwords | unlock_offline_clear | 
| Report offline password unlocking | unlock_offline_pd | 
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback