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

Mall UI BizBundle

Last Updated on : 2022-09-16 09:03:00download

Description

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.

Integrate with the UI BizBundle

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

source "https://github.com/tuya/tuya-pod-specs"
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

target 'your_target_name' do
  # TuyaSmart SDK
  pod "TuyaSmartHomeKit"
  # Adds the Mall BizBundle.
  pod 'TuyaSmartMallBizBundle'
end

Service protocols

Provide services

The UI BizBundle relies on the implementation of the protocol TYMallProtocol to provide services. You can view the TYMallProtocol.h file in the TYModuleServices component.

#import <Foundation/Foundation.h>

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

@protocol TYMallProtocol <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 `TYMallPageType`
 * You should replace mall page every time after logged user changed.
 * @param pageType Mall page type
 */
- (void)requestMallPage:(TYMallPageType)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 `TYMallPageType`
 * @param pageType Mall page type
 */
- (void)requestMallUrlWithPage:(TYMallPageType)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

Depend on services

None.

Usage instruction

Things to note

  1. Before the call of any API method, make sure that the user has logged in to the app.
  2. Before the mall pages are returned, check whether the App Mall service is enabled for the region in which the current user is registered. The App Mall service is strongly correlated with user information.
  3. If the user status is changed, you must check the availability of the Mall UI BizBundle to reload the mall pages.
  4. The mall pages are returned as UIViewController. UINavigationController must be used to call the push or present method.
  5. The mall pages depend on the navigation controller, and navigation content settings are required. Therefore, the navigation controller must encapsulate the mall pages and navigation content.

Query availability status

ObjC:

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

id<TYMallProtocol> mallImpl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYMallProtocol)];
[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 = TuyaSmartBizCore.sharedInstance().service(of: TYMallProtocol.self)
(mallImpl as? TYMallProtocol)?.checkIfMallEnable(forCurrentUser: { (enable, error) in
    if let e = error {
        print("\(e)")
        return
    }
    print("\(enable)")
})

Check whether App Mall is enabled for current user’s region

ObjC:

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

id<TYMallProtocol> mallImpl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYMallProtocol)];
[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 = TuyaSmartBizCore.sharedInstance().service(of: TYMallProtocol.self)
(mallImpl as? TYMallProtourl)?.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)")
})

Get mall pages (UIViewController)

The following mall pages are returned:

  • Home: TYMallPageTypeHome
  • Orders: TYMallPageTypeOrders

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 <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)
})

Get mall pages (PageUrl)

The following mall pages are returned:

  • Home: TYMallPageTypeHome
  • Orders: TYMallPageTypeOrders

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 <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYMallProtocol.h>

id<TYMallProtocol> mallImpl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYMallProtocol)];
[impl requestMallUrlWithPage:TYMallPageTypeHome completionBlock:^(NSString *pageUrl, NSError *error) {
		// The page URL.
		
    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)?.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)
})

Get 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 <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TYMallProtocol.h>

id<TYMallProtocol> mallImpl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYMallProtocol)];
[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 = TuyaSmartBizCore.sharedInstance().service(of: TYMallProtocol.self)
(mallImpl as? TYMallProtocol)?.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)
})

FAQs

Q: The system asynchronously checks whether to display the mall and a latency exists in the process of loading the tab page. How do I optimize this process?

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.

Q: After a floating window appears above the mall page or after navigation to a custom page, the tab bar disappears. How do I fix this problem?

  1. To deal with the navigation from the mall tab page to a custom page, apply this setting: self.navigationController.navigationBarHidden = NO.
  2. To deal with the navigation from a custom page to the mall tab page, apply this setting: self.navigationController.navigationBarHidden = YES.

Q: An error has occurred while loading the mall tab page. How do I fix the problem?

  1. Check whether the test device has the system time modified.
  2. Check whether the app domain name is correct.

Q: The navigation to the mall page failed. How do I fix the problem?

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.

Q: How can I modify the logic of displaying the mall tab page?

  1. requestMallUrlWithPage is used to obtain the URL of the homepage or orders page for the mall.
  2. Modify the parameters in UrlParams:
    • _ty_hideNav=1: displays the mall tab page.
    • _ty_hideNav=0: hides the mall tab page.