Manage User Accounts

Last Updated on : 2023-05-25 06:23:50

Modify account information

Change a user avatar

Compliance issues and certain risks might be caused if users are allowed to upload a custom avatar. To protect you from these potential issues and risks, this API method is deprecated. Modify your app features accordingly and avoid using this API method.

Parameters

Parameter Description
headIcon The image of the avatar.
success The success callback.
failure The failure callback. An error message is returned.

Example

ObjC:

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

Swift:

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

Set temperature unit to Celsius or Fahrenheit.

API description

- (void)updateTempUnitWithTempUnit:(NSInteger)tempUnit
                           success:(nullable ThingSuccessHandler)success
                           failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
tempUnit The temperature unit. Valid values:
  • 1: °C
  • 2: °F
success The success callback.
failure The failure callback. An error message is returned.

Example

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

Swift:

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

Modify the nickname

API description

- (void)updateNickname:(NSString *)nickName
               success:(nullable ThingSuccessHandler)success
               failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
nickName The nickname.
success The success callback.
failure The failure callback. An error message is returned.

Example

ObjC:

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

Swift:

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

Update user’s time zone

API description

- (void)updateTimeZoneWithTimeZoneId:(NSString *)timeZoneId
                             success:(nullable ThingSuccessHandler)success
                             failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
timeZoneId The time zone ID. Example: Asia/Shanghai.
success The success callback.
failure The failure callback. An error message is returned.

Example

ObjC:

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

Swift:

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

Update user’s location

API description

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

Parameters

Parameter Description
latitude The latitude of the user.
longitude The longitude of the user.

Example

ObjC:

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

Swift:

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

Log out or switch between accounts

API description

- (void)loginOut:(nullable ThingSuccessHandler)success
         failure:(nullable ThingFailureError)failure;

Parameters

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

Example

ObjC:

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

Swift:

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

Inactivate or delete account

API description

Deletes a user account. During the week following this delete operation, if the user is logged in again, the delete request is canceled. If not, the user is permanently disabled and all its information is deleted after this week.

- (void)cancelAccount:(nullable ThingSuccessHandler)success
              failure:(nullable ThingFailureError)failure;

Parameters

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

Example

ObjC:

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

Swift:

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

Process session expiration

If users reset the password or have not logged in for a long time, an error message is returned to indicate session expiration. In this case, you must listen for the notifications of ThingSmartUserNotificationUserSessionInvalid and navigate users to the login page.

ObjC:

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

- (void)sessionInvalid {
		NSLog(@"sessionInvalid");
		// Navigates to the login page.
		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: "ThingSmartUserNotificationUserSessionInvalid"), object: nil)
}

@objc func sessionInvalid() {
    print("sessionInvalid")
    // Navigates to the login page.
		let vc = MyLoginViewController()
		window.rootViewController = vc
		window.makeKeyAndVisible()
}