成员信息管理(iOS)

更新时间:2024-10-15 09:17:09下载pdf

功能说明

家庭成员管理相关的所有功能对应 TuyaSmartHomeTuyaSmartHomeInvitationTuyaSmartHomeMember 类,成员角色类型 TYHomeRoleType

类名(协议名) 说明
TuyaSmartHomeMember 家庭成员管理

添加家庭成员

拥有者(TYHomeRoleType_Owner)可以添加管理员及以下角色,管理员(TYHomeRoleType_Admin)仅仅可以添加普通成员及以下角色。

接口说明

TuyaSmartHomeAddMemberRequestModelautoAccept 用于控制受是否需要受邀请者同意。若设置为 NO,则受邀请者需要调用 TuyaSmartHome - joinFamilyWithAccept:success:failure: 接口同意后才能加入该家庭。

- (void)addHomeMemberWithAddMemeberRequestModel:(TuyaSmartHomeAddMemberRequestModel *)requestModel success:(TYSuccessDict)success failure:(TYFailureError)failure;

参数说明

参数 说明
requestModel 添加成员请求模型
success 成功回调
failure 失败回调

TuyaSmartHomeAddMemberRequestModel 数据模型

字段 类型 描述
name NSString 为受邀请者设置的昵称
account NSString 受邀请账号
countryCode NSString 受邀请者账号对应国家码
role TYHomeRoleType 成员角色
headPic UIImage 为受邀请者设置的头像 nil 时使用受邀请者个人头像
autoAccept BOOL 是否需要受邀请者同意接受邀请
  • YES:受邀请账号自动接受该家庭邀请,无需受邀请者确认
  • NO:需要受邀请者同意后才可加入该家庭

示例代码

Objc:

- (void)addShare {
	[self.smartHome addHomeMemberWithAddMemeberRequestModel:requestModel success:^(NSDictionary *dict) {
		NSLog(@"addNewMember success");
	} failure:^(NSError *error) {
		NSLog(@"addNewMember failure");
	}];
}

Swift:

func addShare() {
	home?.addHomeMember(requestModel: requestModel, success: {
		print("addNewMember success")
	}, failure: { (error) in
		if let e = error {
			print("addNewMember failure: \(e)")
		}
	})
}

删除家庭成员

拥有者(TYHomeRoleType_Owner)可以删除管理员及以下角色,管理员(TYHomeRoleType_Admin)仅仅可以删除普通成员及以下角色。

接口说明

若成员传入自身 memberId,针对不同的家庭成员有一些区别:

  • 家庭管理员、普通成员、自定义角色为离开家庭,此时该家庭未注销,设备也不会被重置。
  • 拥有者为注销家庭,同时该家庭下所有设备会被重置,效果与 注销家庭 一致。
- (void)removeHomeMemberWithMemberId:(long long)memberId
							success:(TYSuccessHandler)success
							failure:(TYFailureError)failure;

参数说明

参数 说明
memberId 家庭成员 ID
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)removeMember:(TuyaSmartHomeMemberModel *)memberModel {
	// self.homeMember = [[TuyaSmartHomeMember alloc] init];
	[self.homeMember removeHomeMemberWithMemberId:memberModel.memberId success:^{
		NSLog(@"removeMember success");
	} failure:^(NSError *error) {
		NSLog(@"removeMember failure: %@", error);
	}];
}

Swift:

func removeMember(_ memberModel: TuyaSmartHomeMemberModel) {
	homeMember?.removeHomeMember(withMemberId: memberModel.memberId, success: {
		print("removeMember success")
	}, failure: { (error) in
		if let e = error {
			print("removeMember failure: \(e)")
		}
	})
}

查询家庭成员列表

接口说明

- (void)getHomeMemberListWithSuccess:(void(^)(NSArray <TuyaSmartHomeMemberModel *> *memberList))success failure:(TYFailureError)failure;

参数说明

参数 说明
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)initMemberList {
 //	_home = [TuyaSmartHome homeWithHomeId:homeId];
	[_home getHomeMemberListWithSuccess:^(NSArray<TuyaSmartHomeMemberModel *> *memberList) {
		NSLog(@"getMemberList success: %@", memberList);
	} failure:^(NSError *error) {
		NSLog(@"getMemberList failure");
	}];
}

Swift:

func initMemberList() {
	home.getHomeMemberList(withSuccess: { memberList in
		print("getMemberList success: \(memberList)")
	}, failure: { (error) in
		if let e = error {
			print("getMemberList failure: \(e)")
		}
	})
}

更新家庭成员的信息

拥有者(TYHomeRoleType_Owner)可以修改管理员及以下角色,管理员(TYHomeRoleType_Admin)仅仅可以修改普通成员及以下角色。

接口说明

- (void)updateHomeMemberInfoWithMemberRequestModel:(TuyaSmartHomeMemberRequestModel *)memberRequestModel success:(TYSuccessHandler)success failure:(TYFailureError)failure;

参数说明

参数 说明
memberRequestModel 家庭成员请求模型
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)modifyMemberName:(TuyaSmartHomeMemberModel *)memberModel name:(NSString *)name {
	// self.homeMember = [[TuyaSmartHomeMember alloc] init];
TuyaSmartHomeMemberRequestModel *requestModel = [[TuyaSmartHomeMemberRequestModel alloc] init];
	[self.homeMember updateHomeMemberInfoWithMemberRequestModel:requestModel success:^{
		NSLog(@"modifyMemberName success");
	} failure:^(NSError *error) {
		NSLog(@"modifyMemberName failure: %@", error);
	}];
}

Swift:

func modifyMember(_ memberModel: TuyaSmartHomeMemberModel, name: String) {
	homeMember?.updateHomeMemberName(withMemberRequestModel:requestModel, success: {
		print("modifyMemberName success")
	}, failure: { (error) in
		if let e = error {
			print("modifyMemberName failure: \(e)")
		}
	})
}

查询添加家庭成员邀请码

接口说明

TuyaSmartHomeInvitation 中有创建邀请码的实例方法。

- (void)createInvitationWithCreateRequestModel:(TuyaSmartHomeInvitationCreateRequestModel *)createRequestModel
									success:(void(^)(TuyaSmartHomeInvitationResultModel *invitationResultModel))success
									failure:(TYFailureError)failure;

TuyaSmartHomeInvitationCreateRequestModelhomeID 为需要邀请成员加入的家庭 ID

参数说明

参数 说明
createRequestModel 创建邀请码请求模型
success 成功回调
failure 失败回调

TuyaSmartHomeInvitationCreateRequestModel 数据模型

字段 类型 描述
homeID long long 家庭 ID
needMsgContent BOOL 是否需要邀请文案信

示例代码

Objc:

TuyaSmartHomeInvitationCreateRequestModel *requestModel = [[TuyaSmartHomeInvitationCreateRequestModel alloc] init];
requestModel.homeID = homeID;
requestModel.needMsgContent = YES;
self.smartHomeInvitation = [[TuyaSmartHomeInvitation alloc] init];
[self.smartHomeInvitation createInvitationWithCreateRequestModel:requestModel success:success failure:failure];

Swift:

let requestModel = TuyaSmartHomeInvitationCreateRequestModel()
requestModel.homeID = homeID
requestModel.needMsgContent = true
self.smartHomeInvitation = TuyaSmartHomeInvitation()
self.smartHomeInvitation.createInvitation(with: requestModel, success: success, failure: failure)

通过邀请码加入一个家庭

接口说明

接口类名为 TuyaSmartHomeInvitation

- joinHomeWithInvitationCode:success:failure:

参数说明

参数 说明
invitationCode 邀请码
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)joinHomeWithInvitationCode:(NSString *)invitationCode
						success:(TYSuccessBOOL)success
						failure:(TYFailureError)failure {
	[self.smartHomeInvitation joinHomeWithInvitationCode:invitationCode success:success failure:failure];
}

Swift:

func joinHome(
	withInvitationCode invitationCode: String?,
	success: @escaping (_ result: Bool) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.joinHome(withInvitationCode: invitationCode, success: success, failure: failure)
}

撤销家庭邀请

接口说明

接口类名为 TuyaSmartHomeInvitation

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
								success:(TYSuccessBOOL)success
								failure:(TYFailureError)failure;

参数说明

参数 说明
invitationID 邀请码
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
								success:(TYSuccessBOOL)success
								failure:(TYFailureError)failure {
	[self.smartHomeInvitation cancelInvitationWithInvitationID:invitationID success:success failure:failure];
}

Swift:

func cancelInvitation(
	withInvitationID invitationID: NSNumber?,
	success: @escaping (_ result: Bool) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.cancelInvitation(withInvitationID: invitationID, success: success, failure: failure)
}

接受或拒绝家庭邀请

接口说明

成员是否接受该家庭的邀请对应 TuyaSmartHomeModel 下的 dealStatus,受邀状态会分别对应 TYHomeStatusPendingTYHomeStatusAcceptTYHomeStatusReject。未接受加入的家庭成员将无法使用该家庭下的设备等功能,拒绝加入家庭后将无法在查询家庭列表接口中查询到该家庭信息。

- (void)joinFamilyWithAccept:(BOOL)accept
					success:(TYSuccessBOOL)success
					failure:(TYFailureError)failure;

参数说明

参数 说明
accept 是否接受
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)initMemberList {
 //	_home = [TuyaSmartHome homeWithHomeId:homeId];
 	[_home joinFamilyWithAccept:YES success:^(BOOL result) {
		NSLog(@"join success");
	} failure:^(NSError *error) {
		NSLog(@"join failure");
	}];
}

Swift:

func initMemberList(_ memberModel: TuyaSmartHomeMemberModel) {
	home?.joinFamilyWithAccept(true, success: { (result: Bool) in
		print("join success")
	}, failure: { (error) in
		if let e = error {
			print("join failure: \(e)")
		}
	})
}

查询邀请成员记录

接口说明

接口类名为 TuyaSmartHomeInvitation

- (void)fetchInvitationRecordListWithHomeID:(long long)homeID
									success:(void(^)(NSArray<TuyaSmartHomeInvitationRecordModel *> *invitationRecordList))success
									failure:(TYFailureError)failure;

参数说明

参数 说明
homeID 家庭 ID
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)fetchInvitationRecordListWithHomeID:(long long)homeID
									success:(void(^)(NSArray<TuyaSmartHomeInvitationRecordModel *> *invitationRecordList))success
									failure:(TYFailureError)failure {
	[self.smartHomeInvitation fetchInvitationRecordListWithHomeID:homeID success:success failure:failure];
}

Swift:

func fetchInvitationHomeInfo(
	withInvitationCode invitationCode: String?,
	success: @escaping (_ homeModel: TuyaSmartHomeModel?) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.fetchInvitationHomeInfo(withInvitationCode: invitationCode, success: success, failure: failure)
}

修改被邀请者信息

接口说明

接口类名为 TuyaSmartHomeInvitation

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(TuyaSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
												success:(TYSuccessBOOL)success
												failure:(TYFailureError)failure;

参数说明

参数 说明
TuyaSmartHomeInvitationInfoRequestModel 邀请信息请求模型
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(TuyaSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
												success:(TYSuccessBOOL)success
												failure:(TYFailureError)failure {
	[self.smartHomeInvitation updateInvitationInfoWithInvitationInfoRequestModel:invitationInfoRequestModel success:success failure:failure];
}

Swift:

func updateInvitationInfo(
	with invitationInfoRequestModel: TuyaSmartHomeInvitationInfoRequestModel?,
	success: @escaping (_ result: Bool) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.updateInvitationInfo(with: invitationInfoRequestModel, success: success, failure: failure)
}