Message Center UI BizBundle

Last Updated on : 2024-07-16 06:28:45download

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 'ThingSmartMessageBizBundle'
end

Service protocols

Provide services

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

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol ThingMessageCenterProtocol <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 ThingSmartHomeDataProtocol 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 ThingSmartHome
 */
- (ThingSmartHome *)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 ThingSmartHomeDataProtocol must be implemented first.

ObjC:

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

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

// Implements the protocol method.
- (ThingSmartHome *)getCurrentHome {
    ThingSmartHome *home = [ThingSmartHome homeWithHomeId:@"Current home 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
    }

}

Open message center

ObjC:

#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)

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.