English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Register and Login with Anonymous Account

Last Updated on : 2022-01-10 04:25:41download

Register and login with anonymous account

API description

- (void)registerAnonymousWithCountryCode:(NSString *)countryCode
                                userName:(NSString *)userName
                                 success:(TYSuccessHandler)success
                                 failure:(TYFailureError)failure;

Parameters

Parameter Type Description
countryCode NSString The country code. For example, 86 means China and 1 means the USA.
userName NSString The nickname used for anonymous login. For example, a device name can be used.
success TYSuccessHandler The success callback.
failure TYFailureError The failure callback. An error message is returned.

Example

ObjC:

NSString *countryCode = @"1"; // The USA.
NSString *usename = [UIDevice currentDevice].name;  // The device name.
[[TuyaSmartUser sharedInstance] registerAnonymousWithCountryCode:countryCode
                                                        userName:usename
                                                         success:^{
	NSLog(@"anonymouse success");
} failure:^(NSError *error) {
	NSLog(@"anonymouse failure: %@", error);
}];

Swift:

let countryCode = "1" // The USA.
let usename = UIDevice.current.name // The device name.
TuyaSmartUser.sharedInstance().registerAnonymous(withCountryCode: countryCode,
                                                        userName: usename,
                                                        success: {
    print("anonymouse success")
}, failure: { error in
    if let error = error {
        print("anonymouse failure: \(error)")
    }
})

Log out of or delete anonymous account

API description

Logs out of an anonymous account. This type of account is deleted immediately after logout. Other types of accounts might be deleted seven days after delete requests are sent.

- (void)deleteAnonymousAccountWithSuccess:(TYSuccessHandler)success
                                  failure:(TYFailureError)failure

Parameters

Parameter Type Description
success TYSuccessHandler The success callback.
failure TYFailureError The failure callback. An error message is returned.

Example

ObjC:

[[TuyaSmartUser sharedInstance] deleteAnonymousAccountWithSuccess:^{
    NSLog(@"anonymous logout success");
} failure:^(NSError *error) {
    NSLog(@"anonymous logout failure: %@", error);
}];

Swift:

TuyaSmartUser.sharedInstance().deleteAnonymousAccount(withSuccess: {
    print("anonymous logout success")
}, failure: { error in
    if let error = error {
        print("anonymous logout failure: \(error)")
    }
})

Bind anonymous account with contact information

API description

Adds a mobile phone number or email address to an anonymous account to change it into a normal account. Perform the following steps:

  1. Verify an email address or mobile phone number.
  2. Reset the password of the account.
- (void)usernameBindingWithCountryCode:(NSString *)countryCode
                              userName:(NSString *)userName
                                  code:(NSString *)code
                              password:(NSString *)password
                               success:(nullable TYSuccessHandler)success
                               failure:(nullable TYFailureError)failure;

Parameters

Parameter Type Description
countryCode NSString* The country code. For example, 86 means China and 1 means the USA.
userName NSString* The mobile phone number or email address to be bound with the account.
code NSString* The verification code.
password NSString* The password to be reset.
success TYSuccessHandler The success callback.
failure TYFailureError The failure callback. An error message is returned.

Example

ObjC:

NSString *countryCode = @"1"; // The USA.
NSString *username = @"example@test.com";   // The email address or mobile phone number to be bound with the account.
NSString *code = @"verify code numbers";    // The verification code sent to the email address or mobile phone number.
NSString *password = @"account password";   // Resets the password of the account.
[[TuyaSmartUser sharedInstance] usernameBindingWithCountryCode:countryCode
                                                          userName:username
                                                              code:code
                                                          password:password
                                                           success:^{
    NSLog(@"username bind success");
} failure:^(NSError *error) {
    NSLog(@"username bind failure:%@", error);
}];

Swift:

let countryCode = "1" // The USA.
let username = "example@test.com" // The email address or mobile phone number to be bound with the account.
let code = "verify code numbers" // The verification code sent to the email address or mobile phone number.
let password = "account password" // Resets the password of the account.
TuyaSmartUser.sharedInstance().usernameBinding(withCountryCode: countryCode, userName: username, code: code, password: password, success: {
    print("username bind success")
}, failure: { error in
    if let error = error {
        print("username bind failure:\(error)")
    }
})