消息中心 UI 业务包

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

涂鸦消息中心 UI 业务包提供涂鸦 App 消息中心业务逻辑。业务功能主要涵盖各类消息的推送历史记录,包括告警、家庭、通知三个消息大类。其中告警包含设备告警、场景自动化等执行记录。

消息中心设置页可以启用或关闭各类消息推送。对于告警类消息,支持添加设备免打扰时段。

接入组件

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

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

target 'your_target_name' do
  # 添加消息中心业务包
  pod 'ThingSmartMessageBizBundle'
end

服务协议

提供服务

消息中心 UI 业务包实现 ThingMessageCenterProtocol 协议以提供对外服务,在 ThingModuleServices 组件中查看 ThingMessageCenterProtocol.h 协议文件内容为:

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol ThingMessageCenterProtocol <NSObject>

/// push消息中心页面 push message center vc
/// @param 动画 animated
- (void)gotoMessageCenterViewControllerWithAnimated:(BOOL)animated;

@end

NS_ASSUME_NONNULL_END

依赖服务

消息中心业务包正常运行需要依赖 ThingSmartHomeDataProtocol 这个协议提供的协议方法,提供当前家庭信息。

/**
 获取当前的家庭,当前没有家庭的时候,返回nil。

 @return ThingSmartHome
 */
- (ThingSmartHome *)getCurrentHome;

使用指南

  • 在使用任何接口之前,请确认用户已登录。
  • 登录用户发生变化时,务必重新判断消息中心可用状态并重新获取消息中心页面。
  • 调用业务包逻辑前,要先实现 ThingSmartHomeDataProtocol 中的 getCurrentHome 方法。

Objective-C 示例

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

- (void)initCurrentHome {
    // 注册要实现的协议
    [[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingSmartHomeDataProtocol) withInstance:self];
}

// 实现对应的协议方法
- (ThingSmartHome *)getCurrentHome {
    ThingSmartHome *home = [ThingSmartHome homeWithHomeId:@"当前家庭id"];
    return home;
}

Swift 示例

import ThingSmartDeviceKit

class ThingMessageCenterTest: NSObject,ThingSmartHomeDataProtocol{

    func test() {
        ThingSmartBizCore.sharedInstance().registerService(ThingSmartHomeDataProtocol.self, withInstance: self)
    }

    func getCurrentHome() -> ThingSmartHome! {
        let home = ThingSmartHome.init(homeId: 111)
        return home
    }

}

进入消息中心

Objective-C 示例

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

- (void)gotoDeviceConfig {
    id<ThingMessageCenterProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMessageCenterProtocol)];
    [impl gotoMessageCenterViewControllerWithAnimated:YES];
}

Swift 示例

let impl = ThingSmartBizCore.sharedInstance().service(of: ThingMessageCenterProtocol.self) as? ThingMessageCenterProtocol
impl?.gotoMessageCenterViewController(animated: true)

因 UI 业务包开放能力及功能组件依赖原因,消息中心部分告警信息链接点击响应暂时不支持。