成员信息管理(iOS)

更新时间:2024-08-15 10:00:20下载pdf

功能说明

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

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

添加家庭成员

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

接口说明

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

- (void)addHomeMemberWithAddMemeberRequestModel:(ThingSmartHomeAddMemberRequestModel *)requestModel success:(ThingSuccessDict)success failure:(ThingFailureError)failure;

参数说明

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

ThingSmartHomeAddMemberRequestModel 数据模型

字段 类型 描述
name NSString 为受邀请者设置的昵称
account NSString 受邀请账号
countryCode NSString 受邀请者账号对应国家码
role ThingHomeRoleType 成员角色
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)")
        }
    })
}

删除家庭成员

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

接口说明

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

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

参数说明

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

示例代码

Objc:

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

Swift:

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

查询家庭成员列表

接口说明

- (void)getHomeMemberListWithSuccess:(void(^)(NSArray <ThingSmartHomeMemberModel *> *memberList))success failure:(ThingFailureError)failure;

参数说明

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

示例代码

Objc:

- (void)initMemberList {
 // _home = [ThingSmartHome homeWithHomeId:homeId];
    [_home getHomeMemberListWithSuccess:^(NSArray<ThingSmartHomeMemberModel *> *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)")
        }
    })
}

更新家庭成员的信息

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

接口说明

- (void)updateHomeMemberInfoWithMemberRequestModel:(ThingSmartHomeMemberRequestModel *)memberRequestModel success:(ThingSuccessHandler)success failure:(ThingFailureError)failure;

参数说明

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

示例代码

Objc:

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

Swift:

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

查询添加家庭成员邀请码

接口说明

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

- (void)createInvitationWithCreateRequestModel:(ThingSmartHomeInvitationCreateRequestModel *)createRequestModel
                                    success:(void(^)(ThingSmartHomeInvitationResultModel *invitationResultModel))success
                                    failure:(ThingFailureError)failure;

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

参数说明

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

ThingSmartHomeInvitationCreateRequestModel 数据模型

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

示例代码

Objc:

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

Swift:

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

通过邀请码加入一个家庭

接口说明

接口类名为 ThingSmartHomeInvitation

- joinHomeWithInvitationCode:success:failure:

参数说明

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

示例代码

Objc:

- (void)joinHomeWithInvitationCode:(NSString *)invitationCode
                        success:(ThingSuccessBOOL)success
                        failure:(ThingFailureError)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)
}

撤销家庭邀请

接口说明

接口类名为 ThingSmartHomeInvitation

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
                                success:(ThingSuccessBOOL)success
                                failure:(ThingFailureError)failure;

参数说明

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

示例代码

Objc:

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
                                success:(ThingSuccessBOOL)success
                                failure:(ThingFailureError)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)
}

接受或拒绝家庭邀请

接口说明

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

- (void)joinFamilyWithAccept:(BOOL)accept
                    success:(ThingSuccessBOOL)success
                    failure:(ThingFailureError)failure;

参数说明

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

示例代码

Objc:

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

Swift:

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

查询邀请成员记录

接口说明

接口类名为 ThingSmartHomeInvitation

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

参数说明

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

示例代码

Objc:

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

Swift:

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

修改被邀请者信息

接口说明

接口类名为 ThingSmartHomeInvitation

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(ThingSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
                                                success:(ThingSuccessBOOL)success
                                                failure:(ThingFailureError)failure;

参数说明

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

示例代码

Objc:

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(ThingSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
                                                success:(ThingSuccessBOOL)success
                                                failure:(ThingFailureError)failure {
    [self.smartHomeInvitation updateInvitationInfoWithInvitationInfoRequestModel:invitationInfoRequestModel success:success failure:failure];
}

Swift:

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