Last Updated on : 2023-06-05 03:22:34download
Tuya Smart Residence App SDK supports login with a verification code that is sent to a user’s email address.
This API does not support app services that are deployed inside mainland China. Therefore, a country code cannot be set to 86
if it is required in this type of app service.
API description
- (void)sendVerifyCodeByRegisterEmail:(NSString *)countryCode
email:(NSString *)email
success:(nullable TYSuccessHandler)success
failure:(nullable TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
countryCode | The country code. Example: 1 . |
The email address. | |
success | The success callback. |
failure | The failure callback. An error message is returned to indicate the cause. |
Example
Objective-C:
[[TuyaSmartUser sharedInstance] sendVerifyCodeByRegisterEmail:@"your_country_code" email:@"your_email" success:^{
NSLog(@"sendVerifyCode success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCode failure: %@", error);
}];
Swift:
TuyaSmartUser.sharedInstance()?.sendVerifyCode(byRegisterEmail: "your_country_code", email: "your_email", success: {
print("sendVerifyCode success")
}, failure: { (error) in
if let e = error {
print("sendVerifyCode failure: \(e)")
}
})
API description
Verifies a verification code that is used for login, registration, or password resetting with an email address.
- (void)checkCodeWithUserName:(NSString *)userName
region:(NSString *_Nullable)region
countryCode:(NSString *)countryCode
code:(NSString *)code
type:(NSInteger)type
success:(TYSuccessBOOL)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
userName | The email address of the user. |
region | The area in which the account is registered. Default value: nil . |
countryCode | The country code. Example: 1 . |
code | The verification code received and entered by the user. |
type | The purpose of the verification code. Valid values:
|
success | The success callback. |
failure | The failure callback. An error message is returned to indicate the cause. |
Example
Objective-C:
[[TuyaSmartUser sharedInstance] checkCodeWithUserName:@"email_or_phone_number" region:@"region" countryCode:@"your_country_code" code:@"verify_code" type:1 success:^(BOOL result) {
if (result) {
NSLog(@"valid code!");
} else {
NSLog(@"invalid code!");
}
} failure:^(NSError *error) {
NSLog(@"check code failure: %@", error);
}];
Swift:
TuyaSmartUser.sharedInstance()?.checkCode(withUserName: "email_or_phone_number", region: "region", countryCode: "your_country_code", code: "verify_code", type: type, success: { (result) in
if result {
print("valid code!")
} else {
print("invalid code!")
}
}, failure: { (error) in
if let error = error {
print("check code failure: \(error)")
}
})
To allow users to register an account with an email address, you must make an API request to send a verification code.
API description
- (void)registerByEmail:(NSString *)countryCode
email:(NSString *)email
password:(NSString *)password
code:(NSString *)code
success:(nullable TYSuccessHandler)success
failure:(nullable TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
countryCode | The country code. Example: 1 . |
The email address. | |
password | The password. |
code | The verification code received and entered by the user. |
success | The success callback. |
failure | The failure callback. An error message is returned to indicate the cause. |
Example
Objective-C:
[[TuyaSmartUser sharedInstance] registerByEmail:@"your_country_code" email:@"your_email" password:@"your_password" code:@"verify_code" success:^{
NSLog(@"register success");
} failure:^(NSError *error) {
NSLog(@"register failure: %@", error);
}];
Swift:
TuyaSmartUser.sharedInstance()?.register(byEmail: "your_country_code", email: "your_email", password: "your_password", code: "verify_code", success: {
print("register success")
}, failure: { (error) in
if let e = error {
print("register failure: \(e)")
}
})
API description
- (void)loginByEmail:(NSString *)countryCode
email:(NSString *)email
password:(NSString *)password
success:(nullable TYSuccessHandler)success
failure:(nullable TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
countryCode | The country code. Example: 1 . |
The email address. | |
password | The password. |
success | The success callback. |
failure | The failure callback. An error message is returned to indicate the cause. |
Example
Objective-C:
[[TuyaSmartUser sharedInstance] loginByEmail:@"your_country_code" email:@"your_email" password:@"your_password" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];
Swift:
TuyaSmartUser.sharedInstance()?.login(byEmail: "your_country_code", email: "your_email", password: "your_password", success: {
print("login success")
}, failure: { (error) in
if let e = error {
print("login failure: \(e)")
}
})
To allow users to reset the password of an account that is registered with an email address, you must make an API request to send a verification code.
API description
- (void)resetPasswordByEmail:(NSString *)countryCode
email:(NSString *)email
newPassword:(NSString *)newPassword
code:(NSString *)code
success:(nullable TYSuccessHandler)success
failure:(nullable TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
countryCode | The country code. Example: 1 . |
The email address. | |
newPassword | The new password. |
code | The verification code received and entered by the user. |
success | The success callback. |
failure | The failure callback. An error message is returned to indicate the cause. |
Example
Objective-C:
- (void)resetPasswordByEmail {
[TuyaSmartUser sharedInstance] resetPasswordByEmail:@"your_country_code" email:@"your_email" newPassword:@"your_password" code:@"verify_code" success:^{
NSLog(@"resetPasswordByEmail success");
} failure:^(NSError *error) {
NSLog(@"resetPasswordByEmail failure: %@", error);
}];
}
Swift:
func resetPasswordByEmail() {
TuyaSmartUser.sharedInstance()?.resetPassword(byEmail: "your_country_code", email: "your_email", newPassword: "your_password", code: "verify_code", success: {
print("resetPasswordByEmail success")
}, failure: { (error) in
if let e = error {
print("resetPasswordByEmail failure: \(e)")
}
})
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback