English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Mall UI BizBundle

Last Updated on : 2022-06-23 10:17:53download

Introduction

H5 Mall provides a container that hosts the “App Mall”, so that your app has powerful mall capabilities and allows mobile traffic to be realized through the mall.

“App Mall” is a value-added service provided by the Tuya IoT Development Platform. For more information, you can search for “App Mall” in Tuya’s Value-added Service.

Integrate

Add the TuyaSmartMallBizBundle in the project’s Podfile file and execute the pod update command.

source "https://github.com/tuya/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'

target 'your_target_name' do
  # TuyaSmart SDK
  pod "TuyaSmartHomeKit"
  # Add H5 Mall BizBundle
  pod 'TuyaSmartMallBizBundle', '~> 3.22.0'
end

Service protocol

Service provided by BizBundle

The H5 mall BizBundle implements the TYMallProtocol protocol to provide services. View the TYMallProtocol.h file in the TYModuleServices as follows:

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, TYMallPageType) {
    TYMallPageTypeHome,      // Mall home page
    TYMallPageTypeOrders,    // Mall orders page
};

@protocol TYMallProtocol <NSObject>

/**
 * Check if the mall is enabled for the current logged user.
 * You should check this every time after the logged user changes.
 */
- (void)checkIfMallEnableForCurrentUser:(void(^)(BOOL enable, NSError *error))callback;

/**
 * Request a particular mall page with `TYMallPageType`
 * You should replace the mall page every time after the logged user changes.
 * @param pageType Mall page type
 */
- (void)requestMallPage:(TYMallPageType)pageType completionBlock:(void(^)(__kindof UIViewController *page, NSError *error))callback;

@end

Service required by BizBundle

None.

User guidance

Precautions

  1. Before using any method, be sure to confirm that the user is logged in.
  2. Before obtaining any mall page, you need to first confirm whether the service area registered by the current user is open for the mall.
  3. When the login user changes, be sure to re-check the mall availability status and re-acquire the mall page.
  4. Get the mall page as UIViewController, be sure to use UINavigationController to push or present it.

The mall page depends on the navigation controller and sets the navigation bar content.

Check mall availability

Objective-C

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

id<TYMallProtocol> mallImpl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYMallProtocol)];
[mallImpl checkIfMallEnableForCurrentUser:^(BOOL enable, NSError *error) {
  if (error) {
    // Return error when query fails
    NSLog(@"%@",error);
  } else {
    // enable is true, the mall is available, otherwise it is not available
    NSLog(@"%@",@(enable));
  }
}];

Swift

let mallImpl = TuyaSmartBizCore.sharedInstance().service(of: TYMallProtocol.self)
(mallImpl as? TYMallProtocol)?.checkIfMallEnable(forCurrentUser: { (enable, error) in
    if let e = error {
        print("\(e)")
        return
    }
    print("\(enable)")
})

Get mall page (UIViewController)

Two pages are currently provided:

  • Mall index page (TYMallPageTypeHome)
  • Mall orders page (TYMallPageTypeOrders)

You can obtain the corresponding page to display according to your needs.

Objective-C

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

id<TYMallProtocol> mallImpl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYMallProtocol)];
[impl requestMallPage:TYMallPageTypeHome completionBlock:^(__kindof UIViewController *page, NSError *error) {
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:page];
    [self presentViewController:nav animated:YES completion:nil];
}];

Swift

let mallImpl = TuyaSmartBizCore.sharedInstance().service(of: TYMallProtocol.self)
(mallImpl as? TYMallProtocol)?.request(.home, completionBlock: { (mallVc, error) in
    if let e = error {
        print("\(e)")
        return
    }
    // push
    yourNaviController.pushViewController(mallVc!, animated: true)
    // present
    let naviVc = UINavigationController.init(rootViewController: mallVc!)
    yourViewController.present(naviVc, animated: true, completion: nil)
})