管理用户账号信息

更新时间:2022-03-03 06:41:17下载pdf

修改用户账号信息

修改用户的自定义头像

参数说明

参数 说明
headIcon 头像图像
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)updateHeadIcon:(UIImage *)headIcon {
	[[TuyaSmartUser sharedInstance] updateHeadIcon:headIcon success:^{
		NSLog(@"update head icon success");
	} failure:^(NSError *error) {
		NSLog(@"update head icon failure: %@", error);
	}];
}

Swift:

func updateHeadIcon(_ headIcon: UIImage) {
    TuyaSmartUser.sharedInstance()?.updateHeadIcon(headIcon, success: {
        print("update head icon success")
    }, failure: { (error) in
        if let e = error {
            print("update head icon failure: \(e)")
        }
    })
}

选择摄氏温度或者华氏温度

接口描述

- (void)updateTempUnitWithTempUnit:(NSInteger)tempUnit
                           success:(nullable TYSuccessHandler)success
                           failure:(nullable TYFailureError)failure;

参数说明

参数 说明
tempUnit 温度单位
  • 1:°C
  • 2:°F
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

- (void)updateTempUnitWithTempUnit:(NSInteger)tempUnit {
	[[TuyaSmartUser sharedInstance] updateTempUnitWithTempUnit:tempUnit success:^{
		NSLog(@"update temp unit success");
	} failure:^(NSError *error) {
		NSLog(@"update temp unit failure: %@", error);
	}];
}

Swift:

func updateTempUnit(withTempUnit tempUnit: Int) {
    TuyaSmartUser.sharedInstance().updateTempUnit(withTempUnit: tempUnit, success: {
        print("update temp unit success")
    }, failure: { error in
        if let error = error {
            print("update temp unit failure: \(error)")
        }
    })
}

修改用户账号昵称

接口描述

- (void)updateNickname:(NSString *)nickName
               success:(nullable TYSuccessHandler)success
               failure:(nullable TYFailureError)failure;

参数说明

参数 说明
nickName 昵称
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)modifyNickname:(NSString *)nickname {
	[[TuyaSmartUser sharedInstance] updateNickname:nickname success:^{
		NSLog(@"updateNickname success");
	} failure:^(NSError *error) {
		NSLog(@"updateNickname failure: %@", error);
	}];
}

Swift:

func modifyNickname(_ nickName: String) {
    TuyaSmartUser.sharedInstance()?.updateNickname(nickName, success: {
        print("updateNickname success")
    }, failure: { (error) in
        if let e = error {
            print("updateNickname failure: \(e)")
        }
    })
}

更新用户所处的时区

接口描述

- (void)updateTimeZoneWithTimeZoneId:(NSString *)timeZoneId
                             success:(nullable TYSuccessHandler)success
                             failure:(nullable TYFailureError)failure;

参数说明

参数 说明
timeZoneId 时区 ID,例如 Asia/Shanghai
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)updateTimeZoneId:(NSString *)timeZoneId {
	[[TuyaSmartUser sharedInstance] updateTimeZoneWithTimeZoneId:timeZoneId success:^{
		NSLog(@"update timeZoneId success");
	} failure:^(NSError *error) {
		NSLog(@"update timeZoneId failure: %@", error);
	}];
}

Swift:

func updateTimeZoneId(_ timeZoneId: String) {
    TuyaSmartUser.sharedInstance()?.updateTimeZone(withTimeZoneId: timeZoneId, success: {
        print("update timeZoneId success")
    }, failure: { (error) in
        if let e = error {
            print("update timeZoneId failure: \(e)")
        }
    })
}

更新用户的当前定位

接口描述

- (void)updateLatitude:(double)latitude longitude:(double)longitude;

参数说明

参数 说明
latitude 纬度
longitude 经度

示例代码

Objc:

- (void)updateLocation {
  double latitude = 30.000;
  double longitude = 120.000;
  [[TuyaSmartSDK sharedInstance] updateLatitude:latitude longitude:longitude];
}

Swift:

func updateLocation() {
  TuyaSmartSDK.sharedInstance()?.updateLatitude(latitude, longitude: longitude);
}

退出登录或切换账号

接口描述

- (void)loginOut:(nullable TYSuccessHandler)success
         failure:(nullable TYFailureError)failure;

参数说明

参数 说明
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)loginOut {
	[TuyaSmartUser sharedInstance] loginOut:^{
		NSLog(@"logOut success");
	} failure:^(NSError *error) {
		NSLog(@"logOut failure: %@", error);
	}];
}

Swift:

func loginOut() {
    TuyaSmartUser.sharedInstance()?.loginOut({
        print("logOut success")
    }, failure: { (error) in
        if let e = error {
            print("logOut failure: \(e)")
        }
    })
}

停用或注销用户账号

接口描述

注销账号后,一周后才会永久注销并删除用户账户中的所有信息。但是,如果用户在永久注销之前重新登录的话,则注销请求会被取消。

- (void)cancelAccount:(nullable TYSuccessHandler)success
              failure:(nullable TYFailureError)failure;

参数说明

参数 说明
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)cancelAccount {
	[TuyaSmartUser sharedInstance] cancelAccount:^{
		NSLog(@"cancel account success");
	} failure:^(NSError *error) {
		NSLog(@"cancel account failure: %@", error);
	}];
}

Swift:

func cancelAccount() {
    TuyaSmartUser.sharedInstance()?.cancelAccount({
        print("cancel account success")
    }, failure: { (error) in
        if let e = error {
            print("cancel account failure: \(e)")
        }
    })
}

处理登录会话过期

如果用户账号长期未登录,或者账号修改了密码,在访问服务的过程中会返回 Session 过期的错误。此时,您需要监听 TuyaSmartUserNotificationUserSessionInvalid 通知,跳转至登录页面,引导用户重新登录。

Objc:

- (void)loadNotification {
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionInvalid) name:TuyaSmartUserNotificationUserSessionInvalid object:nil];
}

- (void)sessionInvalid {
		NSLog(@"sessionInvalid");
		//跳转至登录页面
		MyLoginViewController *vc = [[MyLoginViewController alloc] init];
		self.window.rootViewController = vc;
	  [self.window makeKeyAndVisible];
}

Swift:

func loadNotification() {
    NotificationCenter.default.addObserver(self, selector: #selector(sessionInvalid), name: NSNotification.Name(rawValue: "TuyaSmartUserNotificationUserSessionInvalid"), object: nil)
}

@ObjC func sessionInvalid() {
    print("sessionInvalid")
    //跳转至登录页面
		let vc = MyLoginViewController()
		window.rootViewController = vc
		window.makeKeyAndVisible()
}