更新时间:2024-07-16 06:28:45下载pdf
涂鸦 H5 商城 UI 业务包提供承载 App 商城 的 iOS 容器,让您的 IoT App 具备丰富的商城能力,让移动端流量通过商城变现。App 商城 是嵌入在 App 的全球电商平台,详情请访问 App 商城。
在工程的 Podfile
文件中添加商城业务包组件,并执行 pod update
命令。
source "https://github.com/tuya/tuya-pod-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>
#import "ThingMallInfo.h"
typedef NS_ENUM(NSUInteger, ThingMallPageType) {
ThingMallPageTypeHome, // Mall home page
ThingMallPageTypeOrders, // Mall orders page
};
typedef void(^ThingMallInfoCompletion)(ThingMallInfo * _Nullable mall, NSError * _Nullable error);
@protocol ThingMallProtocol <NSObject>
/**
* Get the store jump link and switch information.
* Only one successful request will be executed per app lifecycle, and thereafter the cached data will be returned.
* Always use cache first.
*/
- (void)fetchMallInfoWithCompletion:(ThingMallInfoCompletion)completion;
/**
* Request special mall page with `ThingMallPageType`
* You should replace the mall page every time after the logged user has changed.
* @param pageType Mall page type
*/
- (void)requestMallPage:(ThingMallPageType)pageType completionBlock:(void(^)(__kindof UIViewController *page, NSError *error))callback;
/**
* Request special mall page with url
* You should replace the mall page every time after the logged user has changed.
* @param url Mall url
*/
- (void)requestMallPageWithUrl:(NSString *)url completionBlock:(void(^)(__kindof UIViewController *page, NSError *error))callback;
/**
* After the successful call of the fetchMallInfoWithCompletion method, you can directly obtain the cached information.
*/
- (ThingMallInfo * _Nullable)cachedMallInfo;
/**
* Mall view controller, maybe MiniApp Container, H5 Container
*/
- (UIViewController *)mallViewController;
#pragma mark deprecated
/**
* Check if mall is enabled for currently logged user.
* You should check this every time after logged user changed.
*/
- (void)checkIfMallEnableForCurrentUser:(void(^)(BOOL enable, NSError *error))callback __attribute__((deprecated("use fetchMallInfoWithCompletion: instead.")));
/**
* Request special mall url with `ThingMallPageType`
* @param pageType Mall page type
*/
- (void)requestMallUrlWithPage:(ThingMallPageType)pageType completionBlock:(void(^)(NSString *url, NSError *error))callback __attribute__((deprecated("use fetchMallInfoWithCompletion: instead.")));
@end
无。
UIViewController
,请使用 UINavigationController
进行 push
或 present
展示。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)
})
Objective-C 示例
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[mallImpl fetchMallInfoWithCompletion:^(ThingMallInfo * _Nullable mall, NSError * _Nullable error) {
if (error) {
// 查询失败时返回 error
NSLog(@"%@",error);
} else {
if (mall.enableMall) {
// enable 为 true 则商城可用,否则不可用
NSLog(@"%@",@(enable));
}
}
}];
Swift 示例
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self) as? ThingMallProtocol
mallImpl?.fetchMallInfo(completion: { mallInfo, error in
if let e = error {
print("\(e)")
return
}
if ((mallInfo?.enableMall()) != nil) {
}
})
目前提供以下两个页面:
ThingMallPageTypeHome
ThingMallPageTypeOrders
接入时,可以根据需要获取对应页面路由地址,然后根据 Url
获取 ViewController
。获取到 Url
之后,您可以对部分参数进行调整。
Objective-C 示例
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingMallProtocol.h>
id<ThingMallProtocol> mallImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingMallProtocol)];
[mallImpl fetchMallInfoWithCompletion:^(ThingMallInfo * _Nullable mall, NSError * _Nullable error) {
f (error) {
} else if (mall.mallURL) {
}
}];
Swift 示例
let mallImpl = ThingSmartBizCore.sharedInstance().service(of: ThingMallProtocol.self) as? ThingMallProtocol
mallImpl?.fetchMallInfo(completion: { mallInfo, error in
if let e = error {
print("\(e)")
return
}
if let url = mallInfo?.mallURL() {
}
})
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
:表示不展示商城导航栏。该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈