Advanced Functions UI BizBundle

Last Updated on : 2023-04-13 09:33:00download

The Advanced Functions UI BizBundle provides a container for iOS that hosts the app’s advanced functions. The following advanced functions are available.

Integrate with the UI BizBundle

Add the components of the Advanced Functions UI BizBundle to Podfile and run the command pod update.

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

target 'your_target_name' do
  # Adds the Advanced Functions UI BizBundle.
  pod 'ThingPersonalServiceModule'
end

Service protocol

Provide services

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

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, ThingPersonalServiceType) {
    ThingPersonalServiceTypePushCall, // Phone notification
    ThingPersonalServiceTypePushSMS,  // Short message service
};

@protocol ThingPersonalServiceProtocol <NSObject>

/**
* Gets the value-added service page.
*
* @param type The type of the value-added service.
* @param callback This block should contain a parameter of UIViewController type and a parameter of NSError type.
*/
- (void)requestPersonalService:(ThingPersonalServiceType)type completionBlock:(void(^)(__kindof UIViewController *page, NSError *error))callback;
@end

Depend on services

None.

Usage instruction

Things to note

  • Before the call of any API method, make sure that the user has logged in to the app.
  • Before the advanced function pages are returned, check whether the advanced function service is enabled for the region in which the current user is registered. The service is strongly correlated with user information.
  • The advanced function pages are returned as UIViewController. UINavigationController must be used to call the push or present method.
  • The advanced function pages depend on the navigation controller, and navigation content settings are required. Therefore, the navigation controller must encapsulate the advanced function pages and navigation content.

Get advanced function pages (UIViewController)

The following advanced function pages are returned:

  • Phone notification: ThingPersonalServiceTypePushCall
  • Short message service: ThingPersonalServiceTypePushSMS

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 other pages might fail.

#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingPersonalServiceProtocol.h>

id<ThingPersonalServiceProtocol> psImpl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingPersonalServiceProtocol)];
[self requestPersonalService:ThingPersonalServiceTypePushSMS completionBlock:^(__kindof UIViewController *page, NSError *error) {
  if (error) {
    NSLog(@"%@",error);
  } else {
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:page];
    [self presentViewController:nav animated:YES completion:nil];
  }
}];

Swift

let psImpl = ThingSmartBizCore.sharedInstance().service(of: ThingPersonalServiceProtocol.self)
(psImpl as? ThingPersonalServiceProtocol)?.request(.home, completionBlock: { (psVc, error) in
    if let e = error {
        print("\(e)")
        return
    }
    // push
    yourNaviController.pushViewController(psVc!, animated: true)
    // present
    let naviVc = UINavigationController.init(rootViewController: psVc!)
    yourViewController.present(naviVc, animated: true, completion: nil)
})