Message Center UI BizBundle

Last Updated on : 2023-05-22 06:38:29

Message Center UI BizBundle provides the service logic of the message center. The message center keeps the history of push notifications that are classified into alerts, home messages, and notifications. Alerts include device alerts and smart scene history.

On the message center settings page, users can enable or disable one or more push notifications. DND periods can be added for device alerts.

Integrate with the UI BizBundle

Add the components of the Message Center UI BizBundle to the Podfile and run the command pod update.

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

target 'your_target_name' do
  # Adds the UI BizBundle.
  pod 'TuyaSmartMessageBizBundle'
end

Service protocols

Provide services

The UI BizBundle relies on the implementation of the protocol TYMessageCenterProtocol to provide services. You can view the file TYMessageCenterProtocol.h in the component TYModuleServices.

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol TYMessageCenterProtocol <NSObject>

/// The page of push notifications.
/// @param The animation effect.
- (void)gotoMessageCenterViewControllerWithAnimated:(BOOL)animated;

@end

NS_ASSUME_NONNULL_END

Depend on services

The UI BizBundle depends on the method provided by the protocol TYSmartHomeDataProtocol to get the current home details required for pairing.

/**
 Returns the current home. If the current user does not have a home, `nil` is returned.

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

Usage instruction

  • Before the call of any API method, make sure that the user has logged in to the app.
  • If the user status is changed, you must check the availability of the Message Center UI BizBundle to reload the message center page.
  • Before the UI BizBundle is used, the getCurrentHome method provided by the protocol TYSmartHomeDataProtocol must be implemented first.

ObjC:

#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYSmartHomeDataProtocol.h>

- (void)initCurrentHome {
    // Registers the protocol to be implemented.
    [[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYSmartHomeDataProtocol) withInstance:self];
}

// Implements the protocol method.
- (TuyaSmartHome *)getCurrentHome {
    TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:@"Current home ID"];
    return home;
}

Swift:

import TuyaSmartDeviceKit

class TYMessageCenterTest: NSObject,TYSmartHomeDataProtocol{

    func test() {
        TuyaSmartBizCore.sharedInstance().registerService(TYSmartHomeDataProtocol.self, withInstance: self)
    }

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

}

Open message center

ObjC:

#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYMessageCenterProtocol.h>

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

Swift:

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

Due to the open capabilities and component dependencies of the UI BizBundle, the message center might not respond when users tap certain types of alerts.