更新时间:2023-07-13 07:14:38下载pdf
涂鸦 H5 商城 UI 业务包提供承载 App 商城 的 iOS 容器,让您的 IoT App 具备丰富的商城能力,让移动端流量通过商城变现。App 商城 是嵌入在 App 的全球电商平台,详情请访问 App 商城。
在工程的 Podfile
文件中添加商城业务包组件,并执行 pod update
命令:
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"
# 添加 H5 商城业务包
pod 'ThingSmartMallBizBundle'
end
H5 商城 UI 业务包实现 ThingMallProtocol
协议以提供服务,在 ThingModuleServices
组件中查看 ThingMallProtocol.h
协议文件内容为:
#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
无。
UIViewController
,请使用 UINavigationController
进行 push
或 present
展示。Objective-C 示例
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[mallImpl checkIfMallEnableForCurrentUser:^(BOOL enable, NSError *error) {
if (error) {
// 查询失败时返回 error
NSLog(@"%@",error);
} else {
// enable 为 true 则商城可用,否则不可用
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)")
})
Objective-C 示例
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[mallImpl getMallEnabledFromCloud:^(BOOL enable, NSString *url) {
if (error) {
// 查询失败时返回 error
NSLog(@"%@",error);
} else {
// enable 为 true 则商城可用,否则不可用
// Url为当前商城首页的页面地址
NSLog(@"%@",url);
}
}];
Swift 示例
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self)
(mallImpl as? ThingMallProtourl)?.getMallEnabledFromCloud(forCurrentUser: { (enable, url) in
if let e = error {
print("\ 用户所注册的服务区未否开通商城服务")
return
}
print("\(url)")
})
UIViewController
)目前提供以下两个页面:
ThingMallPageTypeHome
ThingMallPageTypeOrders
接入时,您可以根据需要获取对应页面来展示。因为后续还需要重新 Push 新的页面。必须包装 NavigationController
。否则,会导致后续页面无法跳转。
Objective-C 示例
#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)
})
目前提供以下两个页面:
接入时,可以根据需要获取对应页面路由地址,然后根据 Url
获取 ViewController
。获取到 Url
之后,您可以对部分参数进行调整。
Objective-C 示例
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[impl requestMallUrlWithPage:ThingMallPageTypeHome completionBlock:^(NSString *pageUrl, NSError *error) {
// 页面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)
})
Url
获取页面 ViewController
针对注册过域名白名单的服务,您可以通过此方法根据页面 Url
生成一个 ViewController
。
Objective-C 示例
#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)
})
A:用户登录成功后,即可调用 checkIfMallEnableForCurrentUser
来判断是否需要展示商城。回调完成后,即可重新加载 Tab 商城页面。异步的操作判断无法避免。
self.navigationController.navigationBarHidden = NO
。self.navigationController.navigationBarHidden = YES
。页面跳转默认采用 ‘self.navigationController Push’。商城服务获取到的是一个UIViewController
,需要增加外部套一个UINavigationController
后,才可以添加到 UITabbarController
。
requestMallUrlWithPage
获取商城主页或订单页的页面地址。UrlParams
里面的参数:
_ty_hideNav=1
:表示展示商城导航栏。_ty_hideNav=0
:表示不展示商城导航栏。该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈