# SDK Initialization

Before using Mini-Program APIs, you need to initialize the Mini-Program SDK first. Only after the SDK is successfully initialized can you use the APIs provided by the SDK; otherwise, API calls will fail.

# 1. Initialization

There are two APIs for initializing the SDK. It is recommended to use the second one (MopSDK.initSDK).

1、Not recommended (will not be maintained in the future)

/**
   * @description 
   * @param {Object} params 
   * @param {string} params.appkey 
   * @param {string} params.secret 
   * @param {string} params.apiServer 
   * @param {string} params.apiPrefix 
   * @param {string} params.userId 
   * @param {string} params.appletText  Inject the generic term string for Mini-Programs, defaults to "Mini-Program".
   * @param {number} params.language  The language type of the SDK, defaults to Chinese. 0: Chinese, 1: English. For other languages, use the customLanguagePath and localeLanguage properties. Refer to the documentation for details.
   * @param {string} params.customLanguagePath  【iOS Property】 Customize the language of the SDK, priority is higher than the built-in language property; Example: If placed under mainBundle, set the relative path: @"abc.lproj"; If placed under a custom Bundle, set the relative path: @"bundleName.bundle/abc.lproj"
   * @param {string} params.localeLanguage 【Android Property】 Customize the language of the SDK, priority is higher than the built-in language property; For language list reference: https://uutool.cn/info-i18n/ or Java class 【java.util.Locale】; Example: Simplified Chinese: zh_CN, Traditional Chinese: zh_TW, English: en
   * @param {Object} param.nativeEventEmitter eventEmitter instance
   * @param {Object} param.finMopSDK  nativeModules.FINMopSDK reference
   * @returns 
   */
  MopSDK.initialize(params)

Initialization example:

import MopSDK from 'react-native-mopsdk';
import { NativeModules, NativeEventEmitter } from 'react-native';

const eventEmitter = new NativeEventEmitter(NativeModules.FINMopSDK);
MopSDK.initialize(
      {
        appkey: 'xxxxxxx',
secret: 'xxxxxxx',
apiServer: 'xxxxxxx',
userId: '123456',
language: 0, // Defaults to Chinese; 0: Chinese, 1: English
customLanguagePath:"br.lproj",//【iOS Property】If placed under mainBundle, set the relative path: @"abc.lproj"; if placed under a custom Bundle, set the relative path: @"bundleName.bundle/abc.lproj"
appletText:"Lightweight Application", // If you need to modify the Chinese "Mini-Program" or English "Mini-Program" in the public UI, you need to set the appletText property.
localeLanguage:"ja_JP",// 【Android Property】Customize the language of the SDK, priority is higher than the built-in language property; For language list reference: https://uutool.cn/info-i18n/ or Java class 【java.util.Locale】; Example: Simplified Chinese: zh_CN, Traditional Chinese: zh_TW, English: en
nativeEventEmitter: eventEmitter,
finMopSDK: NativeModules.FINMopSDK
      }
    ).then((res) => {
      console.log('message: ', res);
      const s = JSON.stringify(res);
      this.setState({
        status: 'native callback received',
        message: s,
      });
    }).catch((error) => {
      console.log('init error: ', error);
      const s = 'initialize fail'
      this.setState({
        status: 'native callback received',
        message: s,
      });
    })

2、Recommended

/**
   * @description Initialize the SDK with the provided configuration
   * @param {Object} params
   * @param {Config} params.config - Main SDK configuration
   * @param {UIConfig} params.uiConfig - UI related configuration
   * @param {Object} params.finMopSDK 
   * @param {Object} params.nativeEventEmitter 
   * @returns 
   */
  MopSDK.initSDK(params)

Initialization example:

import { NativeModules, NativeEventEmitter } from 'react-native';
// There are many configuration items. Import the corresponding classes needed for initialization based on the comments above the method.
// All configuration-related classes and constants are: BOOLState, ConfigPriority, LogLevel, LanguageType, FinStoreConfig, Config, CapsuleConfig, NavHomeConfig, FloatWindowConfig, AuthButtonConfig, AuthViewConfig, UIConfig ;
// Import as needed.

import MopSDK, { Config, FinStoreConfig,BOOLState, UIConfig } from 'react-native-mopsdk';

    const eventEmitter = new NativeEventEmitter(NativeModules.FINMopSDK);

    
    let finStoreConfigA = new FinStoreConfig(
      "xxxxxxxx",
      "xxxxxxxx",
      "xxxxxxxx");

    // Multiple servers can be configured
    let finStoreConfigs = [finStoreConfigA];

    let config = new Config(finStoreConfigs,    
                            {userId:"123456789",
                             debug:true,
                             appletDebugMode:BOOLstate.BOOLStateTrue
                            }) ;
    let uiConfig = new UIConfig({isHideClearCacheMenu:true});
    let params = {
      config: config,
      uiConfig: uiConfig,
      finMopSDK: NativeModules.FINMopSDK,
      nativeEventEmitter: eventEmitter
    }

    MopSDK.initSDK(params).then((res) => {
      console.log('message: ', res);
      const s = JSON.stringify(res);
      this.setState({
        status: 'native callback received',
        message: s,
      });
    }).catch((error) => {
      console.log('init error: ', error);
      const s = 'initialize fail'
      this.setState({
        status: 'native callback received',
        message: s,
      });
    })

# FinStoreConfig Configuration Items

Configuration Name Type Required Description
sdkKey string Yes The sdkKey generated when creating the application
sdkSecret string Yes The sdkSecret generated when creating the application
apiServer string Yes Server address, the backend address deployed by the customer
apmServer string No The server address for APM event reporting, uses apiServer if not set
cryptType string No Network interface encryption type. Defaults to "MD5", can also be set to "SM" (National Secret)
fingerprint string No SDK fingerprint, must be passed in certificate-linked environments, otherwise interface access will fail
encryptServerData boolean No Defaults to false. Currently can only be set to false, setting to true will cause interface access failure
enablePreloadFramework boolean No Defaults to true. Whether to pre-download the Base Library. If set to false, the Base Library will not be pre-downloaded during SDK initialization

# 2. Configuration Items

The configuration items during SDK initialization are Config and UIConfig.

  • Config mainly contains configuration items unrelated to the UI;
  • UIConfig mainly contains UI-related configuration items.

# 2.1 Configuration Items in Config

Configuration Name Type Configuration Description
finStoreConfigs Array<FinStoreConfig> List of server configuration objects to initialize, specific parameters see the FinStoreConfig table
userId string Unique identifier for the current user, Mini-Program cache information will be isolated by userId
productIdentification string Product identifier, affects the cache root directory and the identifier in userAgent
disableRequestPermissions boolean Whether to disable the SDK from triggering permission requests, defaults to false. If set to true, APIs using permissions within the SDK will not actively request permissions.
appletAutoAuthorize boolean Whether a confirmation dialog pops up when applying for permissions, defaults to false. If set to true, automatically applies for permissions from the SDK without showing a dialog
disableGetSuperviseInfo boolean Whether to disable the SDK's supervision interface API, defaults to false. If set to true, the SDK disables the supervision interface API (getSuperviseInfo)
appletIntervalUpdateLimit int Number of Mini-Programs automatically checked for updates in the background, value range: 0~50. 0 means no update check; default is 3 if not set.
apmExtendInfo Map<string, string> Extended information for APM statistics. Map type
startCrashProtection boolean Whether to enable Crash protection, default value is false (only supported on iOS). UnrecognizedSelector, KVO, Notification, Timer, Container (array out of bounds, dictionary inserting nil, etc.), String (out of bounds, nil, etc.)
enableApmDataCompression boolean Whether to compress data when reporting APM data, default value is false
encryptServerData boolean Whether the data returned by the platform interface should be encrypted, default value is false.
appletDebugMode BOOLState Whether to enable the Mini-Program's debug mode, i.e., show vConsole.
enableWatermark boolean Whether to display the watermark, default value is false.
watermarkPriority ConfigPriority Watermark display priority setting, global configuration takes priority by default
baseLoadingViewClass string Custom loading view class name for Mini-Programs, only supported on iOS
baseLoadFailedViewClass string Load failure view class name for Mini-Programs, only supported on iOS
header Map<string, string> Uniformly set the headers for network requests within Mini-Programs
headerPriority ConfigPriority Header priority setting, global configuration takes priority by default
enableH5AjaxHook boolean Whether to enable the hook function for H5 pages loaded in Mini-Programs, defaults to false. Only supported on iOS, see comments in the API for details
h5AjaxHookRequestKey string After enabling enableH5AjaxHook, request hooks will be applied, requestKey can be set. Only supported on iOS
pageCountLimit int Maximum limit for the page stack within Mini-Programs. Default value is 0, meaning no limit.
schemes List<string> Custom scheme array. The SDK internally supports WeChat, Alipay, FinClip App, tel schemes by default
debug boolean Set debug mode, affects debugging and logging.
maxRunningApplet int Set the maximum number of Mini-Programs running simultaneously. Only supported on Android
webViewMixedContentMode int WebView mixed content mode. Only supported on Android
bindAppletWithMainProcess boolean Whether the Mini-Program process is bound to the main process, default value is false. When set to true, if the App is killed, the Mini-Program closes synchronously. Only supported on Android
killAppletProcessNotice string Prompt text when closing the Mini-Program after the App is killed. Only supported on Android
enableScreenShot boolean Whether to allow screenshots and screen recording, defaults to true. Only supported on Android
screenShotPriority ConfigPriority Priority setting for screenshot/screen recording configuration, defaults to GLOBAL. Only supported on Android
logLevel LogLevel Log recording level, defaults to NONE.
logMaxAliveSec int Maximum cache time for log files, in seconds, defaults to 10 days.
logDir string Directory where log files are saved.
enablePreNewProcess boolean Whether to create processes in advance, defaults to true. Only supported on Android
language LanguageType Language type for the SDK's public UI, defaults to Chinese
customLanguagePath string Relative path for custom language in the SDK's public UI, priority is higher than the language property (only effective on iOS platform)
localeLanguage string Customize the language of the SDK, priority is higher than the built-in language property (only effective on Android platform), for language list reference: https://uutool.cn/info-i18n/ or Java class 【java.util.Locale】. Example: Simplified Chinese: zh_CN, Traditional Chinese: zh_TW, English: en
useLocalTbsCore boolean Whether to use local loading of the TBS kernel, defaults to false. Only supported on Android
tbsCoreUrl string Download address for the TBS kernel, excluding the filename. Only supported on Android
enableJ2V8 boolean Whether to enable j2v8, defaults to false. Only supported on Android
backgroundFetchPeriod int Time interval for periodic updates (hours), setting to 0 will not initiate periodic update requests, acceptable range is 3-12 hours

# 2.2 Configuration Items in UIConfig

Configuration Name Type Configuration Description
navigationTitleTextAttributes Map<string, any> Navigation bar title style, currently only supports font configuration. Only supported on iOS
navigationBarHeight double Navigation bar height, defaults to 44. Only supported on iOS
navigationBarTitleLightColor string Navigation bar title Light color (color under system dark theme), default value is white #ffffffff
navigationBarTitleDarkColor string Navigation bar title Dark color (color under system light theme), default value is black #ff000000
navigationBarBackBtnLightColor string Navigation bar back button Light color (color under system dark theme), default value is white
navigationBarBackBtnDarkColor string Navigation bar back button Dark color (color under system light theme), default value is black
moreMenuStyle int Style of the popup menu view 0: Default 1: Normal
isHideBackHomePriority ConfigPriority Priority setting for hiding the navigation bar back-to-home button, global configuration takes priority by default. Only supported on iOS
isAlwaysShowBackInDefaultNavigationBar boolean Whether to always show the back button when the navigation bar is the default navigation bar, default value is false. Only supported on Android
isClearNavigationBarNavButtonBackground boolean Whether to clear the background of navigation bar buttons, defaults to false. Only supported on Android
isHideFeedbackAndComplaints boolean Hide the 【Feedback and Complaints】 menu in the ... popup menu, defaults to false
isHideBackHome boolean Hide the 【Back to Home】 menu in the ... popup menu. Defaults to false
isHideForwardMenu boolean Hide the 【Forward】 menu in the ... popup menu, defaults to false
isHideShareAppletMenu boolean Hide the 【Share】 menu in the ... popup menu, defaults to true
isHideAddToDesktopMenu boolean Hide the 【Add to Desktop】 menu in the ... popup menu, defaults to true
isHideFavoriteMenu boolean Hide the 【Favorite】 menu in the ... popup menu, defaults to true
isHideRefreshMenu boolean Hide the 【Re-enter Mini-Program】 menu in the ... popup menu, defaults to false
isHideSettingMenu boolean Hide the 【Settings】 menu in the ... popup menu, defaults to false
capsuleConfig CapsuleConfig Style configuration for the Capsule Button in the upper right corner, specific parameters see the CapsuleConfig table
navHomeConfig NavHomeConfig Style configuration for the back-to-home button, specific parameters see the NavHomeConfig table
floatWindowConfig FloatWindowConfig Android floating window style configuration, specific parameters see the FloatWindowConfig table. Only supported on Android
authViewConfig AuthViewConfig Authorization dialog style configuration, specific parameters see the AuthViewConfig table.
webViewProgressBarColor string Progress bar color when loading H5 pages within Mini-Programs Format #FFFFFFFF
hideWebViewProgressBar boolean Hide the progress bar when loading H5 pages within Mini-Programs, defaults to false
autoAdaptDarkMode boolean Whether to adapt to Dark Mode, default value is false
appendingCustomUserAgent string Content to append to the userAgent.
transtionStyle TranstionStyle Default animation method when opening a Mini-Program. Defaults to TranstionStyleUp. Can be set for the following scenarios: 1. Opening Mini-Program via scheme; 2. Opening Mini-Program via universal link; 3. Animation method for navigateToMiniprogram. Only supported on iOS
hideTransitionCloseButton boolean Whether to hide the close button on the Mini-Program loading page, defaults to false.
disableSlideCloseAppletGesture boolean Whether to disable the swipe-to-close Mini-Program gesture, defaults to false.
appletText string Defaults to "Mini-Program", you need to replace the displayed name. For example, set to "Lightweight Application", all places showing "Mini-Program" will change to "Lightweight Application"
loadingLayoutCls string Loading page Class, only supported on Android
useNativeLiveComponent boolean Whether to use the built-in live component, defaults to false.

# 2.3 Configuration Items in CapsuleConfig (Capsule)

Configuration Name Type Configuration Description
capsuleWidth double Capsule width
capsuleHeight double Capsule height
capsuleRightMargin double Distance from the capsule's right border to the screen's right border
capsuleCornerRadius double Capsule corner radius
capsuleBorderWidth double Capsule border width
capsuleBgLightColor string Capsule light background color, used under system dark theme, default color android:#33000000, iOS:#80ffffff
capsuleBgDarkColor string Capsule dark background color, used under system light theme, default color android:#80ffffff, iOS:#33000000
capsuleBorderLightColor string Capsule light border color, used under system dark theme, default color #80ffffff
capsuleBorderDarkColor string Capsule dark border color, used under system dark theme, default color #26000000
capsuleDividerLightColor string Capsule light divider color, used under system dark theme, default color #80ffffff
capsuleDividerDarkColor string Capsule dark divider color, used under system dark theme, default color #26000000
moreLightImage int Capsule light more button image, not yet supported
moreDarkImage int Capsule dark more button image, not yet supported
moreBtnWidth double Capsule more button width, height equals width, android default value 32; ios default value 20
moreBtnLeftMargin double More button left margin, android default value 6; ios default value 12
closeLightImage int Capsule light close button image, not yet supported
closeDarkImage int Capsule dark close button image, not yet supported
closeBtnWidth double Capsule close button width, android default value 32; ios default value 20
closeBtnLeftMargin double Capsule close button left margin, android default value 6; ios default value 12

# 2.4 Configuration Items in NavHomeConfig (Back to Home Button)

Configuration Name Type Configuration Description
width double Back to home button width
height double Back to home button height
leftMargin double Distance from the back to home button's left side to the screen's left border, Android default value 8, iOS default value 10
cornerRadius double Back to home button corner radius, default value 5
borderWidth borderWidth Back to home button border width, Android default value 0.75, iOS default value 0.8
borderLightColor string Back to home button light border color, default value #80ffffff
borderDarkColor string Back to home button dark border color, default value #26000000
bgLightColor string Back to home button light background color, default value #33000000
bgDarkColor string Back to home button dark background color, default value #80ffffff

# 2.5 Configuration Items for AuthViewConfig (Permission Dialog)

Configuration Name Type Configuration Description
appletNameTextSize double Mini-Program name font size, defaults to 16
appletNameLightColor string Mini-Program name light color (light mode), default #ff222222
appletNameDarkColor string Mini-Program name dark color (dark mode), default #ffd0d0d0
authorizeTitleTextSize double Permission title font size, default size 17
authorizeTitleLightColor string Permission title light color (light mode), default #ff222222
authorizeTitleDarkColor string Permission title dark color (dark mode), default #ffd0d0d0
authorizeDescriptionTextSize double Permission description font size, default size 14
authorizeDescriptionLightColor string Permission description light color (light mode), default #ff666666
authorizeDescriptionDarkColor string Permission description dark color (dark mode), default #ff5c5c5c
agreementTitleTextSize double Agreement title font size, default size 16
agreementTitleLightColor string Agreement title light color (light mode), default #ff222222
agreementTitleDarkColor string Agreement title dark color (dark mode), default #ffd0d0d0
agreementDescriptionTextSize double Agreement description font size, default size 14
agreementDescriptionLightColor string Agreement description light color (light mode), default #ff222222
agreementDescriptionDarkColor string Agreement description dark color (dark mode), default #ffd0d0d0
linkLightColor string Link light color (light mode), default #ff4285f۴
linkDarkColor string Link dark color (dark mode), default #ff4285f۴
allowButtonLightConfig AuthButtonConfig Allow button configuration (light mode), detailed configuration see AuthButtonConfig
allowButtonDarkConfig AuthButtonConfig Allow button configuration (dark mode), detailed configuration see AuthButtonConfig
rejectButtonLightConfig AuthButtonConfig Reject button configuration (light mode), detailed configuration see AuthButtonConfig
rejectButtonDarkConfig AuthButtonConfig Reject button configuration (dark mode), detailed configuration see AuthButtonConfig

# 2.6 Configuration Items for AuthButtonConfig (Buttons in Permission Dialog)

Configuration Name Type Configuration Description
cornerRadius double Button corner radius
normalBackgroundColor string Button default background color
pressedBackgroundColor string Button pressed background color
normalTextColor string Button default text color
pressedTextColor string Button pressed text color
normalBorderColor string Button default border color
pressedBorderColor string Button pressed border color

Our default capsule looks like this:

Then, we only need to set it like this to make it rounded:

CapsuleConfig capsuleConfig = new CapsuleConfig({capsuleCornerRadius:16});
UIConfig uiconfig = new UIConfig({capsuleConfig:capsuleConfig});

The effect is as follows:

© FinClip with ❤ , Since 2017