家庭管理 UI 业务包

更新时间:2023-09-19 03:01:04下载pdf

涂鸦家庭管理 UI 业务包主要包括家庭管理、成员管理、房间管理等业务,这些是对配网后的设备进行管理的基础条件,家庭也是场景智能执行的最大单位。

设备配网后,用户可设置家庭中设备所处的房间。同时,家庭下拥有不同权限的家庭成员对应着不同的操作权限。

接入组件

在工程的 Podfile 文件中添加家庭业务包组件,并执行 pod update 命令:

source 'https://github.com/tuya/tuya-pod-specs.git'
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

target 'your_target_name' do
  # 涂鸦 SDK
  pod "ThingSmartHomeKit"
  # 添加 UI 业务包
  pod 'ThingSmartFamilyBizBundle'
end

服务协议

家庭业务包实现 ThingFamilyProtocol 协议以提供服务,在 ThingModuleServices 组件中查看 ThingFamilyProtocol.h 协议文件内容为:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef void(^DoneActionBlock)(NSString *changedName);

/// Family Management Service
@protocol ThingFamilyProtocol <NSObject>

@optional

/// jump to Family Management ViewController
- (void)gotoFamilyManagement;

/// update current family id , make sure call this method whenever you change the current family id
- (void)updateCurrentFamilyId:(long long)familyId;

/// get current family id , you can create a `ThingSmartHome` instance by calling the class method `[ThingSmartHome homeWithHomeId:currentFamilyId]`.
- (long long)currentFamilyId;

/// clear current family id cache
- (void)clearCurrentFamily;

@end

注意事项

  • 调用任何接口之前,请确认用户已登录。
  • 调用 - (long long)currentFamilyId; 获取当前家庭 ID 前,您需要在家庭变更后,调用 - (void)updateCurrentFamilyId:(long long)familyId 更新当前家庭 ID。
  • 确保 thing_custom_config.json 内的 is_support_home_manager 值为 true

跳转到家庭管理页面

Objective-C 示例

#import <ThingModuleServices/ThingModuleServices.h>
#import <ThingSmartBizCore/ThingSmartBizCore.h>

id<ThingFamilyProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingFamilyProtocol)];
if ([impl respondsToSelector:@selector(gotoFamilyManagement)]) {
    [impl gotoFamilyManagement];
}

Swift 示例

guard let impl = ThingSmartBizCore.sharedInstance().service(of: ThingFamilyProtocol.self) as? ThingFamilyProtocol else {
    return
}
impl.gotoFamilyManagement?()

邀请家庭成员

家庭设置 页面有 添加成员 功能,目前有两类邀请方式:

  • 邀请码:用户在 家庭管理 > 加入一个家庭 页面输入邀请码,加入一个新家庭。
  • 账号邀请:用户进入 家庭管理 页面后,会显示 待加入家庭,点击可以接受或者拒绝。

判断新邀请家庭

通过 ThingSmartHomeModeldealStatus 判断是否是新邀请家庭。

typedef NS_ENUM(NSUInteger, ThingHomeStatus) {
    ThingHomeStatusPending = 1,      /**< 待加入 受邀者未决定是否加入对应家庭 Not deciding whether to join the home */
    ThingHomeStatusAccept,           /**< 受邀者已同意加入对应家庭 The invitee has agreed to join the home */
    ThingHomeStatusReject            /**< 受邀者已拒绝加入对应家庭 The invitee have refused to join the home */
};

弹出邀请弹窗

若要实现实时弹出邀请弹窗的功能,您可以通过设置 ThingSmartHomeManager 的代理实现:

- (void)homeManager:(ThingSmartHomeManager *)manager didAddHome:(ThingSmartHomeModel *)home;

Objective-C 示例

ThingSmartHomeManager *manager = [ThingSmartHomeManager new];
manager.delegate = self;

//....
//以下为当前控制器代理实现代码部分

- (void)homeManager:(ThingSmartHomeManager *)manager didAddHome:(ThingSmartHomeModel *)homeModel {
    if (homeModel.dealStatus <= ThingHomeStatusPending && homeModel.name.length > 0) {
    ///弹出接受邀请弹窗代码

    ///接受邀请
    ThingSmartHome *home = [ThingSmartHome homeWithHomeId:homeModel.homeId];
    [home joinFamilyWithAccept:YES success:^(BOOL result) {} failure:^(NSError *error) {}];

    ///拒绝邀请
    [home joinFamilyWithAccept:NO success:^(BOOL result) {} failure:^(NSError *error) {}];
    }
}

Swift 示例

let manager = ThingSmartHomeManager()
manager.delegate = self

//....
//以下为当前控制器代理实现代码部分

func homeManager(_ manager: ThingSmartHomeManager!, didAddHome homeModel: ThingSmartHomeModel!) {
    if (homeModel.dealStatus.rawValue <= ThingHomeStatus.pending.rawValue) && (homeModel.name.isEmpty == false) {
        ///弹出接受邀请弹窗代码

        ///接受邀请
        let home = ThingSmartHome(homeId: homeModel.homeId)
        home?.joinFamily(withAccept: true, success: { (result) in

        }, failure: { (error) in

        })

        ///拒绝邀请
        home?.joinFamily(withAccept: false, success: { (result) in

        }, failure: { (error) in

        })

    }
}