更新时间:2023-05-22 06:38:25下载pdf
涂鸦家庭管理 UI 业务包主要包括家庭管理、成员管理、房间管理等业务,这些是对配网后的设备进行管理的基础条件,家庭也是场景智能执行的最大单位。
设备配网后,用户可设置家庭中设备所处的房间。同时,家庭下拥有不同权限的家庭成员对应着不同的操作权限。
在工程的 Podfile
文件中添加家庭业务包组件,并执行 pod update
命令:
source 'https://github.com/tuya/tuya-private-specs.git'
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'
target 'your_target_name' do
# 涂鸦 SDK
pod "TuyaSmartHomeKit"
# 添加 UI 业务包
pod 'TuyaSmartFamilyBizBundle'
end
家庭业务包实现 TYFamilyProtocol
协议以提供服务,在 TYModuleServices
组件中查看 TYFamilyProtocol.h
协议文件内容为:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
typedef void(^DoneActionBlock)(NSString *changedName);
/// Family Management Service
@protocol TYFamilyProtocol <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 `TuyaSmartHome` instance by calling the class method `[TuyaSmartHome homeWithHomeId:currentFamilyId]`.
- (long long)currentFamilyId;
/// clear current family id cache
- (void)clearCurrentFamily;
@end
- (long long)currentFamilyId;
获取当前家庭 ID 前,您需要在家庭变更后,调用 - (void)updateCurrentFamilyId:(long long)familyId
更新当前家庭 ID。ty_custom_config.json
内的 is_support_home_manager
值为 true
。Objective-C 示例
#import <TYModuleServices/TYModuleServices.h>
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
id<TYFamilyProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYFamilyProtocol)];
if ([impl respondsToSelector:@selector(gotoFamilyManagement)]) {
[impl gotoFamilyManagement];
}
Swift 示例
guard let impl = TuyaSmartBizCore.sharedInstance().service(of: TYFamilyProtocol.self) as? TYFamilyProtocol else {
return
}
impl.gotoFamilyManagement?()
在 家庭设置 页面有 添加成员 功能,目前有两类邀请方式:
通过 TuyaSmartHomeModel
的 dealStatus
判断是否是新邀请家庭。
typedef NS_ENUM(NSUInteger, TYHomeStatus) {
TYHomeStatusPending = 1, /**< 待加入 受邀者未决定是否加入对应家庭 Not deciding whether to join the home */
TYHomeStatusAccept, /**< 受邀者已同意加入对应家庭 The invitee has agreed to join the home */
TYHomeStatusReject /**< 受邀者已拒绝加入对应家庭 The invitee have refused to join the home */
};
若要实现实时弹出邀请弹窗的功能,您可以通过设置 TuyaSmartHomeManager
的代理实现:
- (void)homeManager:(TuyaSmartHomeManager *)manager didAddHome:(TuyaSmartHomeModel *)home;
Objective-C 示例
TuyaSmartHomeManager *manager = [TuyaSmartHomeManager new];
manager.delegate = self;
//....
//以下为当前控制器代理实现代码部分
- (void)homeManager:(TuyaSmartHomeManager *)manager didAddHome:(TuyaSmartHomeModel *)homeModel {
if (homeModel.dealStatus <= TYHomeStatusPending && homeModel.name.length > 0) {
///弹出接受邀请弹窗代码
///接受邀请
TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:homeModel.homeId];
[home joinFamilyWithAccept:YES success:^(BOOL result) {} failure:^(NSError *error) {}];
///拒绝邀请
[home joinFamilyWithAccept:NO success:^(BOOL result) {} failure:^(NSError *error) {}];
}
}
Swift 示例
let manager = TuyaSmartHomeManager()
manager.delegate = self
//....
//以下为当前控制器代理实现代码部分
func homeManager(_ manager: TuyaSmartHomeManager!, didAddHome homeModel: TuyaSmartHomeModel!) {
if (homeModel.dealStatus.rawValue <= TYHomeStatus.pending.rawValue) && (homeModel.name.isEmpty == false) {
///弹出接受邀请弹窗代码
///接受邀请
let home = TuyaSmartHome(homeId: homeModel.homeId)
home?.joinFamily(withAccept: true, success: { (result) in
}, failure: { (error) in
})
///拒绝邀请
home?.joinFamily(withAccept: false, success: { (result) in
}, failure: { (error) in
})
}
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈