Is this page helpful?
YesNoLast Updated on : 2022-06-23 10:17:53download
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.
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
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
None.
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.
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)")
})
UIViewController
)Two pages are currently provided:
TYMallPageTypeHome
)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)
})
Is this page helpful?
YesNoIs this page helpful?
YesNo