# SDK 初始化

# 1. 初始化

提示

在使用小程序的 API 之前,需要先初始化小程序 SDK。只有成功初始化之后,才能使用 SDK 提供的 API,否则 API 调用会失败。

# API

/**
 * 初始化 FinAppClient 实例。
 * 如果实例已经存在,则更新 context。
 * @param finAppConfig - FinAppClient 的配置。
 * @param entryContext - UIAbilityContext。
 * @param entryInfo - 小程序需要打开的 Ability 的名称。
 * @param startMode - IFinAppStartMode 启动模式的配置项。
 * @returns FinAppClient 的单例实例;所有服务器配置校验失败时返回 null。
 */
FinAppClient.init(finAppConfig: IFinAppConfig.IFinAppConfig, entryContext: common.UIAbilityContext,entryInfo: string, startMode?: IFinAppStartMode): FinAppClient | null

# 2. 配置项

下面各类型都是在 IFinAppConfig 命名空间下,比如 IFinAppConfig.IFinAppConfig 、IFinAppConfig.IStoreConfig

# 2.1 IFinAppConfig 配置项

配置名称 类型 是否必填 说明
finStoreConfigs Array<IStoreConfig> 是 小程序服务器配置信息集合
currentUserId string 否 当前用户唯一标识
appletDebugMode 'default' | 'enable' | 'forbidden' | 'forbiddenRelease' 否 小程序 debug 模式设置。默认为 default;enable 强制所有小程序开启 vConsole;forbidden 强制所有版本关闭 vConsole;forbiddenRelease 强制正式版关闭 vConsole。
productIdentification string 否 产品的标识,配置会将文件夹、UserAgent里的FinClip 等标识改为配置后的值
uiConfig IUIConfig 否 与UI相关的配置项
finKey string 否 SDK 内部配置密钥。
verifyHandler IVerifyHandler 否 外部校验处理函数。
pageCountLimit number 否 小程序中页面栈的最大限制。默认值为0,表示不限制。
memberUserId string 否 当前成员标识。
phone string 否 当前用户手机号。
appletAutoAuthorize boolean 否 申请权限时是否会弹出对话框让用户确认,默认为false。如果设置为true,自动向SDK申请权限,不展示弹框
isApp boolean 否 是否以 App 方式运行。
pickerRegionPath string 否 自定义地区选择器的文件路径,需放在 rawfile 文件夹下
logLevel 'none' | 'info' | 'debug' | 'warn' | 'error' 否 日志等级。默认为 'none',即不输出日志
enableNativeComponent boolean | string[] 否 是否开启同层渲染原生组件。默认为 true。数组支持 input、textarea、video、camera、picker、webview。
channel string 否 渠道标识,如果不填,默认为项目的 BundleID,插件中实现 login 会用到。
schemes string[] 否 自定义 scheme 数组。
header Record<string, string> 否 小程序中网络请求的header
ignoreWebviewCertAuth boolean 否 是否忽略SSL证书校验。默认为false,设置为true时,小程序的web-view组件可加载不受信任的https链接以及http链接
authDescStrategy IFinAppConfig.EAuthDescStrategy 否 小程序权限说明配置策略。None:小程序有配置时显示配置内容;ShowDefault:未配置时显示内置权限信息;Forbidden:不允许申请未配置说明的权限。
enableScreenShot boolean 否 是否允许截屏录屏,默认为true
screenShotPriority IFinAppConfig.EFinAppConfigPriority 否 截屏录屏配置项的优先级,默认 IFinAppConfig.EFinAppConfigPriority.Global。
enableWatermark boolean 否 是否显示水印,默认为false
watermarkPriority IFinAppConfig.EFinAppConfigPriority 否 显示水印优先级设置,默认 IFinAppConfig.EFinAppConfigPriority.Global。
enableWebviewDebug boolean 否 是否开启webview调试,默认为false
language string 否 SDK的语言类型。 目前仅支持中文和英文,默认情况下为中文,不支持的类型也会显示为中文
backgroundFetchPeriod number 否 周期性更新的时间间隔(小时), 设置为0不会发起周期性更新以及数据预拉取请求,接收设置范围为3-12小时

# 2.2 IStoreConfig 配置项

配置名称 类型 是否必填 说明
sdkKey string 是 创建应用时生成的sdkKey
sdkSecret string 是 创建应用时生成的sdkKey
apiServer string 是 服务器地址,客户部署的后台地址
apmServer string 否 apm事件上报的服务器地址,不设置时使用apiServer
cryptType "sm" | "md5" 否 网络接口加密类型。默认为"sm"(国密),也可以设置为"md5"
requestTimeout number 否 单位是 ms,默认为 60s。请求超时时间
encryptUserId boolean 否 (后台接口)是否对userId进行加密传输,需要确保后台服务升级至1.4.1以上,否则加密会导致接口请求失败,默认为false
enablePreloadFramework boolean 否 默认为true。是否预下载基础库,如果设置为false,则初始化SDK时不会预下载基础库

# 2.3 IUIConfig 配置项

配置名称 类型 是否必填 配置描述
capsuleConfig ICapsuleConfig 否 右上角胶囊的样式配置,具体参数见 ICapsuleConfig 表
navHomeConfig INavHomeConfig 否 返回首页按钮的配置的样式配置,具体参数见 INavHomeConfig 表
navBackConfig INavBackConfig 否 返回按钮的配置的样式配置,具体参数见 INavBackConfig 表
navTitleConfig INavTitleConfig 否 导航栏标题样式,具体参数见 INavTitleConfig 表
forwardConfig IForwardConfig 否 转发按钮的样式配置,具体参数见 IForwardConfig 表
imageViewConfig IImageViewConfig 否 更多按钮界面的 Logo 相关配置,具体见 IImageViewConfig 表
webviewComponentProgressBarStyle IWebviewComponentProgressBarConfig 否 webview 加载进度条样式配置,具体参数见 IWebviewComponentProgressBarConfig 表
authViewConfig IAuthViewConfig 否 授权弹框样式配置,具体参数见 IAuthViewConfig 表
navigationBarHeight number 否 导航栏高度,默认值为44
navigationBarTitleLightColor string 否 导航栏标题浅色颜色。
navigationBarTitleDarkColor string 否 导航栏标题深色颜色。
hideBackToHome boolean 否 是否隐藏导航栏中回到首页按钮,默认是 false
hideShareAppletMenu boolean 否 是否隐藏小程序更多菜单中的分享按钮,默认是 true
hideAddToDesktopMenu boolean 否 是否隐藏小程序更多菜单中的添加到桌面按钮,默认是 true
hideForwardMenu boolean 否 是否隐藏更多菜单中的转发按钮,默认是 false
hideRefreshMenu boolean 否 是否隐藏更多菜单中的重新进入按钮,默认是 false
hideSettingMenu boolean 否 是否隐藏小程序更多菜单中的设置按钮,默认是 false
hideDebugMenu boolean 否 是否隐藏更多菜单中打开/关闭调试按钮,默认是 false
hideFavoriteMenu boolean 否 是否隐藏更多菜单中收藏/取消收藏按钮,默认是 true
hideFeedbackMenu boolean 否 是否隐藏更多菜单中反馈投诉按钮,默认是 false
hideClearCacheMenu boolean 否 是否隐藏更多菜单中清除缓存按钮,默认是 false
appletText string 否 小程序文案,默认为“小程序”,你可以设置为"快应用","轻应用"
themeStyle IFinApplet.IThemeStyle 否 主题模式,默认为 Light
appendingCustomUserAgent string 否 要拼接至userAgent中的内容。
navigationBackImage INavigationBackImage 否 导航栏返回按钮图片配置。
isAlwaysShowBackInDefaultNavigationBar boolean 否 当导航栏为默认导航栏时,是否始终显示返回按钮,默认值为false。
moreMenuStyle 'default' | 'normal' | 'page' 否 更多菜单的样式,默认值为 'default'。
mapAlphaOnBackground boolean 否 地图里Hex颜色值透明度是否在后面,比如 true 的时候表示 #RRGGBBAA,false 的时候表示 #AARRGGBB。

IFinApplet.IThemeStyle

名称 描述
Auto 跟随应用
Light 浅色模式
Dark 深色模式

# 2.4 ICapsuleConfig 配置项

配置名称 类型 是否必填 配置描述
hideCapsuleCloseButton boolean 否 隐藏小程序胶囊里的关闭按钮
hideCapsuleMoreButton boolean 否 隐藏小程序胶囊里的更多按钮
hideCapsuleMaxButton boolean 否 是否隐藏胶囊里的最大化按钮。
hideCapsuleMinButton boolean 否 是否隐藏胶囊里的最小化按钮。
hideTransitionCloseButton boolean 否 是否隐藏小程序loading页的关闭按钮
capsuleWidth number 否 胶囊的宽度
capsuleHeight number 否 胶囊的高度
capsuleRightMargin number 否 胶囊的右边框距离屏幕右边框的距离
capsuleCornerRadius number 否 胶囊的圆角半径
capsuleBorderWidth number 否 胶囊的边框宽度
moreBtnWidth number 否 胶囊的更多按钮宽度
moreBtnLeftMargin number 否 更多按钮的左边距
closeBtnWidth number 否 胶囊里关闭按钮的宽度
closeBtnLeftMargin number 否 胶囊里关闭按钮的左边距
maximizeBtnWidth number 否 胶囊里最大化按钮的宽度。
maximizeBtnLeftMargin number 否 胶囊里最大化按钮的左边距。
minimizeBtnWidth number 否 胶囊里最小化按钮的宽度。
minimizeBtnLeftMargin number 否 胶囊里最小化按钮的左边距。
moreLightImage ResourceStr 否 胶囊浅色更多按钮图片。
moreDarkImage ResourceStr 否 胶囊深色更多按钮图片。
closeLightImage ResourceStr 否 胶囊浅色关闭按钮图片。
closeDarkImage ResourceStr 否 胶囊深色关闭按钮图片。
maximizeLightImage ResourceStr 否 胶囊浅色最大化按钮图片。
maximizeDarkImage ResourceStr 否 胶囊深色最大化按钮图片。
normalizeLightImage ResourceStr 否 胶囊浅色还原按钮图片。
normalizeDarkImage ResourceStr 否 胶囊深色还原按钮图片。
minimizeLightImage ResourceStr 否 胶囊浅色最小化按钮图片。
minimizeDarkImage ResourceStr 否 胶囊深色最小化按钮图片。
capsuleBorderLightColor string 否 胶囊的浅色边框颜色
capsuleBorderDarkColor string 否 胶囊的深色边框颜色
capsuleBgLightColor string 否 胶囊的浅色下背景颜色
capsuleBgDarkColor string 否 胶囊的深色下背景颜色
capsuleDividerLightColor string 否 胶囊里浅色分割线颜色
capsuleDividerDarkColor string 否 胶囊里的深色分割线颜色

# 2.5 INavHomeConfig 配置项

配置名称 类型 是否必填 配置描述
width number 否 返回首页按钮的宽度
height number 否 返回首页按钮的高度
leftMargin number 否 返回首页按钮的左侧距离屏幕左边框的距离
cornerRadius number 否 返回首页按钮的圆角半径
borderWidth number 否 返回首页按钮的边框宽度
borderLightColor string 否 返回首页按钮的浅色边框颜色
borderDarkColor string 否 返回首页按钮的深色边框颜色
bgLightColor string 否 返回首页按钮的浅色背景颜色
bgDarkColor string 否 返回首页按钮的深色背景颜色
lightImage ResourceStr 否 返回首页按钮的浅色图片资源地址
darkImage ResourceStr 否 返回首页按钮的深色图片资源地址

# 2.6 INavBackConfig 配置项

配置名称 类型 是否必填 配置描述
width number 否 返回按钮的宽度
height number 否 返回按钮的高度
leftMargin number 否 返回按钮的左侧距离屏幕左边框的距离
lightImage ResourceStr 否 返回按钮的浅色图片资源地址
darkImage ResourceStr 否 返回按钮的深色图片资源地址

# 2.6 INavTitleConfig 配置项

配置名称 类型 是否必填 配置描述
fontSize number 否 导航栏标题字号
fontWeight number | string 否 导航栏标题字重
textAlign string 否 导航栏标题方式,仅支持 left 和 center。

# 2.7 IImageViewConfig 配置项

配置名称 类型 是否必填 配置描述
borderCornerRadius number 否 图片边框圆角半径 默认: 20
borderWidth number 否 图片边框宽度 默认:0.5
borderColor string 否 图片边框颜色 默认: #D8D8D8
backgroundColor string 否 图片背景颜色 默认: #FFF

# 2.8 IForwardConfig 配置项

配置名称 类型 是否必填 配置描述
label string 是 转发按钮的文案
icon ResourceStr 是 转发按钮的图标资源地址
disableIcon ResourceStr 否 转发按钮的禁用图标资源地址
darkIcon ResourceStr 否 转发按钮的深色图标资源地址
disableDarkIcon ResourceStr 否 转发按钮的禁用深色图标资源地址

# 2.9 IWebviewComponentProgressBarConfig 配置项

配置名称 类型 是否必填 配置描述
enable boolean 否 是否启用加载进度条
width number 否 加载进度条的宽度
color string 否 加载进度条的背景色
activeColor string 否 加载进度条的进度色

# 2.10 IAuthViewConfig 配置项

配置名称 类型 是否必填 配置描述
appletNameTextSize number 否 小程序名称字体大小,默认16
appletNameLightColor ResourceColor 否 小程序名称的浅色颜色,默认#222222
appletNameDarkColor ResourceColor 否 小程序名称的深色颜色,默认#d0d0d0
authorizeTitleTextSize number 否 权限标题字体大小,默认17
authorizeTitleLightColor ResourceColor 否 权限标题的浅色颜色,默认#222222
authorizeTitleDarkColor ResourceColor 否 权限标题的深色颜色,默认#d0d0d0
authorizeDescriptionTextSize number 否 权限描述字体大小,默认14
authorizeDescriptionLightColor ResourceColor 否 权限描述的浅色颜色,默认#666666
authorizeDescriptionDarkColor ResourceColor 否 权限描述的深色颜色,默认#5c5c5c
authorizeSelectedLightImage ResourceStr 否 协议选项选中时的浅色icon,大小:22x22
authorizeSelectedDarkImage ResourceStr 否 协议选项选中时的深色icon,大小:22x22
agreementLightImage ResourceStr 否 隐私协议入口浅色icon,大小:22x22
agreementDarkImage ResourceStr 否 隐私协议入口深色icon,大小:22x22
agreementTitleTextSize number 否 协议标题字体大小,默认16
agreementTitleLightColor ResourceColor 否 协议标题的浅色颜色,默认#222222
agreementTitleDarkColor ResourceColor 否 协议标题的深色颜色,默认#d0d0d0
agreementDescriptionTextSize number 否 协议描述字体大小,默认14
agreementDescriptionLightColor ResourceColor 否 协议描述的浅色颜色,默认#222222
agreementDescriptionDarkColor ResourceColor 否 协议描述的深色颜色,默认#d0d0d0
linkLightColor ResourceColor 否 链接的浅色颜色,默认#4285f4
linkDarkColor ResourceColor 否 链接的深色颜色,默认#4285f4
allowButtonLightConfig IAuthButtonConfig 否 同意按钮浅色配置
allowButtonDarkConfig IAuthButtonConfig 否 同意按钮深色配置
rejectButtonLightConfig IAuthButtonConfig 否 拒绝按钮浅色配置
rejectButtonDarkConfig IAuthButtonConfig 否 拒绝按钮深色配置

# 2.11 IAuthButtonConfig 配置项

配置名称 类型 是否必填 配置描述
cornerRadius number 是 按钮的圆角半径
normalBackgroundColor ResourceColor 是 按钮默认背景颜色
pressedBackgroundColor ResourceColor 是 按钮按下背景颜色
normalBorderColor ResourceColor 是 按钮默认边框颜色
pressedBorderColor ResourceColor 是 按钮按下边框颜色
normalTextColor ResourceColor 是 按钮默认文字颜色
pressedTextColor ResourceColor 是 按钮按下文字颜色
© FinClip with ❤ , Since 2017