English
English
简体中文
Contact Us
Register
Log In

Login with UID

Last Updated on : 2023-03-08 08:19:33download

Login with a user ID (UID) is implemented with the API method that integrates with registration and login. This applies to existing accounts. A UID uniquely identifies a user and it is maintained in your user account system.

API description

Automatically enables login if an account is registered, or enables registration and login if the account is not registered.

- (void)loginOrRegisterWithCountryCode:(NSString *)countryCode
                                   uid:(NSString *)uid
                              password:(NSString *)password
                            createHome:(BOOL)createHome
                               success:(nullable TYSuccessID)success
                               failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
countryCode The country code, such as 86.
uid The UID that uniquely identifies a user, without format requirements.
password The random identifier that matches the account ID. Only one identifier is assigned to each account ID. This identifier is not the user’s actual password.
createHome Specifies whether to create a default home.
success The success callback.
failure The failure callback. An error message is returned.

Example

ObjC:

[[TuyaSmartUser sharedInstance] loginOrRegisterWithCountryCode:@"your_country_code" uid:@"your_uid" password:@"your_password" createHome:YES success:^(id result) {
        NSLog(@"loginOrRegisterWithCountryCode success: %@", result);
} failure:^(NSError *error) {
        NSLog(@"loginOrRegisterWithCountryCode failure: %@", error);
}];

Swift:

TuyaSmartUser.sharedInstance()?.loginOrRegisterWithCountryCode("your_country_code", uid: "your_uid", password: "your_password", createHome: true, success: { (result) in
		print("loginOrRegisterWithCountryCode success: \(result)")
}, failure: { (error) in
		if let e = error {
    		print("loginOrRegisterWithCountryCode failure: \(e)")
    }
})