Last Updated on : 2023-07-13 07:14:41download
Mall UI BizBundle provides the iOS container that hosts Tuya’s value-added service App Mall. You can leverage the powerful mall capabilities to monetize the user traffic through your in-app store. For more information, see App Mall.
Add the ThingSmartMallBizBundle
in the project’s Podfile
file and execute the pod update
command.
source "https://github.com/tuya/tuya-private-specs"
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'
target 'your_target_name' do
# ThingSmart SDK
pod "ThingSmartHomeKit"
# Adds the Mall BizBundle.
pod 'ThingSmartMallBizBundle'
end
The UI BizBundle relies on the implementation of the protocol ThingMallProtocol
to provide services. You can view the ThingMallProtocol.h
file in the ThingModuleServices
component.
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, ThingMallPageType) {
ThingMallPageTypeHome, // Mall home page
ThingMallPageTypeOrders, // Mall orders page
};
@protocol ThingMallProtocol <NSObject>
/**
* Check if mall enable for current logged user.
* You should check this every time after logged user changed.
*/
- (void)checkIfMallEnableForCurrentUser:(void(^)(BOOL enable, NSError *error))callback;
/**
* Request special mall page with `ThingMallPageType`
* You should replace mall page every time after logged user changed.
* @param pageType Mall page type
*/
- (void)requestMallPage:(ThingMallPageType)pageType completionBlock:(void(^)(__kindof UIViewController *page, NSError *error))callback;
/**
* Check if mall enable for Cloud
*/
- (void)getMallEnabledFromCloud:(void(^)(BOOL enable , NSString * url))callback;
/**
* Request special mall url with `ThingMallPageType`
* @param pageType Mall page type
*/
- (void)requestMallUrlWithPage:(ThingMallPageType)pageType completionBlock:(void(^)(NSString *url, NSError *error))callback;
/**
* Request special mall page with url
* You should replace mall page every time after logged user changed.
* @param url Mall url
*/
- (void)requestMallPageWithUrl:(NSString *)url completionBlock:(void(^)(__kindof UIViewController *page, NSError *error))callback;
@end
None.
UIViewController
. UINavigationController
must be used to call the push
or present
method.ObjC:
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[mallImpl checkIfMallEnableForCurrentUser:^(BOOL enable, NSError *error) {
if (error) {
// The failure callback.
NSLog(@"%@",error);
} else {
// If `enable` is `true`, it represents that the App Mall service is available. Otherwise, the service is unavailable.
NSLog(@"%@",@(enable));
}
}];
Swift:
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self)
(mallImpl as? ThingMallProtocol)?.checkIfMallEnable(forCurrentUser: { (enable, error) in
if let e = error {
print("\(e)")
return
}
print("\(enable)")
})
ObjC:
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[mallImpl getMallEnabledFromCloud:^(BOOL enable, NSString *url) {
if (error) {
// The failure callback.
NSLog(@"%@",error);
} else {
// If `enable` is `true`, it represents that the App Mall service is available. Otherwise, the service is unavailable.
// `url` represents the URL of the homepage for the mall.
NSLog(@"%@",url);
}
}];
Swift:
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self)
(mallImpl as? ThingMallProtourl)?.getMallEnabledFromCloud(forCurrentUser: { (enable, url) in
if let e = error {
print("\ Check whether the App Mall service is enabled for the region in which the current user is registered.")
return
}
print("\(url)")
})
UIViewController
)The following mall pages are returned:
ThingMallPageTypeHome
ThingMallPageTypeOrders
You can integrate with the UI BizBundle and get these pages as needed. New pages will be pushed later, so NavigationController
must encapsulate UIViewController
. Otherwise, navigation to subsequent pages will be failed.
ObjC:
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[impl requestMallPage:ThingMallPageTypeHome completionBlock:^(__kindof UIViewController *page, NSError *error) {
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:page];
[self presentViewController:nav animated:YES completion:nil];
}];
Swift:
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self)
(mallImpl as? ThingMallProtocol)?.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)
})
The following mall pages are returned:
ThingMallPageTypeHome
ThingMallPageTypeOrders
You can integrate with the UI BizBundle and get routing URLs of these pages as needed. ViewController
can be obtained based on Url
. After Url
is returned, you can modify certain parameters on your terms.
ObjC:
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[impl requestMallUrlWithPage:ThingMallPageTypeHome completionBlock:^(NSString *pageUrl, NSError *error) {
// The page URL.
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:page];
[self presentViewController:nav animated:YES completion:nil];
}];
Swift:
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self)
(mallImpl as? ThingMallProtocol)?.requestMallUrlWithPage(.home, completionBlock: { (pageUrl, 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)
})
ViewController
based on page Url
For the service that is included in the domain name allowlist, you can use this method to generate a ViewController
based on the Url
of the service page.
ObjC:
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[impl requestMallPageWithUrl:@"https://mallpage/pagetext/target" completionBlock:^(__kindof UIViewController *page, NSError *error) {
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:page];
[self presentViewController:nav animated:YES completion:nil];
}];
Swift:
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self)
(mallImpl as? ThingMallProtocol)?.requestMallPageWithUrl("https://mallpage/pagetext/target", 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)
})
After successful login to the app, checkIfMallEnableForCurrentUser
can be called to determine whether to display the mall. At the end of the callback, the mall tab page can be reloaded. This asynchronous operation is required.
self.navigationController.navigationBarHidden = NO
.self.navigationController.navigationBarHidden = YES
.By default, ‘self.navigationController Push’ is used to implement the navigation. A UIViewController
is returned by the mall service and must be encapsulated by UINavigationController
before UINavigationController
can be added to UITabbarController
.
requestMallUrlWithPage
is used to obtain the URL of the homepage or orders page for the mall.UrlParams
:
_ty_hideNav=1
: displays the mall tab page._ty_hideNav=0
: hides the mall tab page.Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback