更新时间:2024-09-06 03:15:02
接口说明
- (void)registerAnonymousWithCountryCode:(NSString *)countryCode
userName:(NSString *)userName
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
参数说明
参数 | 类型 | 说明 |
---|---|---|
countryCode | NSString | 国家码,例如 86 表示中国,1 表示美国 |
userName | NSString | 匿名登录昵称,例如设置为设备名称 |
success | TYSuccessHandler | 接口发送成功回调 |
failure | TYFailureError | 接口发送失败回调,error 表示失败原因 |
示例代码
Objc:
NSString *countryCode = @"1"; // 美国
NSString *usename = [UIDevice currentDevice].name; // 设备名称
[[TuyaSmartUser sharedInstance] registerAnonymousWithCountryCode:countryCode
userName:usename
success:^{
NSLog(@"anonymouse success");
} failure:^(NSError *error) {
NSLog(@"anonymouse failure: %@", error);
}];
Swift:
let countryCode = "1" // 美国
let usename = UIDevice.current.name // 设备名称
TuyaSmartUser.sharedInstance().registerAnonymous(withCountryCode: countryCode,
userName: usename,
success: {
print("anonymouse success")
}, failure: { error in
if let error = error {
print("anonymouse failure: \(error)")
}
})
接口说明
匿名用户账号可以通过这个接口退出登录,匿名账号会立即注销。不过,非匿名用户账号有7天的窗口期。
- (void)deleteAnonymousAccountWithSuccess:(TYSuccessHandler)success
failure:(TYFailureError)failure
参数说明
参数 | 类型 | 说明 |
---|---|---|
success | TYSuccessHandler | 接口发送成功回调 |
failure | TYFailureError | 接口发送失败回调,error 表示失败原因 |
示例代码
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)")
}
})
接口说明
匿名登录的用户可以进一步完善手机或者邮箱信息,转化成正常用户。完善信息通常有两步:
- (void)usernameBindingWithCountryCode:(NSString *)countryCode
userName:(NSString *)userName
code:(NSString *)code
password:(NSString *)password
success:(nullable TYSuccessHandler)success
failure:(nullable TYFailureError)failure;
参数说明
参数 | 类型 | 说明 |
---|---|---|
countryCode | NSString* | 国家码,例如 86 表示中国,1 表示美国 |
userName | NSString* | 用户绑定的手机号码或者邮箱 |
code | NSString* | 验证码 |
password | NSString* | 设置密码 |
success | TYSuccessHandler | 接口发送成功回调 |
failure | TYFailureError | 接口发送失败回调,error 表示失败原因 |
示例代码
Objc:
NSString *countryCode = @"1"; // 美国
NSString *username = @"example@test.com"; // 绑定的邮箱(或手机)
NSString *code = @"verify code numbers"; // 邮箱(或手机)验证码
NSString *password = @"account password"; // 设置账号密码
[[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" // 美国
let username = "example@test.com" // 绑定的邮箱(或手机)
let code = "verify code numbers" // 邮箱(或手机)验证码
let password = "account password" // 设置账号密码
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)")
}
})
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈