更新时间:2024-11-18 11:32:38
灯光场景是针对同房间下的全部灯具进行设置的功能,具有丰富的色盘样式,多样的场景库支持,能快捷方便的设置家庭灯光场景。
灯光场景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
# 添加灯光场景业务包
pod 'TuyaSmartLightSceneBizBundle'
end
灯光场景业务包实现 TYLightSceneProtocol
协议以提供对外服务,在 TYModuleServices
组件中查看 TYLightSceneProtocol
协议文件内容为:
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol TYLightSceneProtocol <NSObject>
/// 添加新场景
- (void)createNewLightScene;
/// 编辑场景
/// @param scene 灯光场景模型
- (void)editLightScene:(TuyaLightSceneModel *)scene;
/// 执行场景
- (void)executeLightScene;
/// 获取灯光场景列表
/// @param homeId 家庭ID
/// @param success 成功回调
/// @param failure 失败回调
- (void)getLightSceneListWithHomeId:(long long)homeId success:(void(^)(NSArray<TuyaLightSceneModel *> * _Nonnull scenes))success failure:(void(^)(NSError * _Nonnull error))failure;
@end
NS_ASSUME_NONNULL_END
在使用任何接口之前,务必确认用户已登录。
调用业务包逻辑前,要先实现 TYSmartHomeDataProtocol
中的协议方法getCurrentHome
。
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYSmartHomeDataProtocol.h>
- (void)initCurrentHome {
// 注册要实现的协议
[[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYSmartHomeDataProtocol) withInstance:self];
}
// 实现对应的协议方法
- (TuyaSmartHome *)getCurrentHome {
TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:@"当前家庭id"];
return home;
}
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYLightSceneProtocol.h>
- (void)createLightScene {
id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
[impl createNewLightScene];
}
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYLightSceneProtocol.h>
- (void)editLightScene {
TuyaLightSceneModel *sceneModel = self.sceneList[indexPath.row];
id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
[impl editLightScene:sceneModel];
}
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYLightSceneProtocol.h>
- (void)executeLightScene {
TuyaLightSceneModel *sceneModel = self.sceneList[indexPath.row];
id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
[impl executeLightScene:sceneModel success:^(BOOL success) {
} failure:^(NSError * _Nonnull error) {
}];
}
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYLightSceneProtocol.h>
- (void)getLightSceneList {
id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
[impl getLightSceneListWithHomeId:'your homeId' success:^(NSArray<TuyaLightSceneModel *> * _Nonnull scenes) {
} failure:^(NSError * _Nonnull error) {
}];
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈