Skip to content

Basics

env

ft.env

Environmental variables

attribute

string USER_DATA_PATH

User directory path in file system (Local path)

base64ToArrayBuffer

ArrayBuffer ft.base64ToArrayBuffer(string base64)

will Base64 String ArrayBuffer object

parameter

string base64

To translate into ArrayBuffer Object Base64 Character string

返回值

ArrayBuffer

ArrayBuffer object

sample code

javascript
const base64 = 'CxYh'
const arrayBuffer = ft.base64ToArrayBuffer(base64)

arrayBufferToBase64

string ft.arrayBufferToBase64(ArrayBuffer arrayBuffer)

will ArrayBuffer Object conversion Base64 Character string

parameter

ArrayBuffer arrayBuffer

To convert Base64 String ArrayBuffer object

Return value

string

Base64 Character string

sample code

javascript
const arrayBuffer = new Uint8Array([11, 22, 33])
const base64 = ft.arrayBufferToBase64(arrayBuffer)

base64ToTempFilePath

Basic library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38

base64ToTempFilePath(Object object)

Save the base64 data of the image to the local sandbox and return the local cache path.

PropertyTypeThe default value isRequiredDescription
xnumber0NoThe upper-left abscissa of the area to be cropped is
ynumber0NoThe upper-left ordinate of the area to be cropped is
widthnumberCanvas width - xNoThe width of the area to be cropped
heightnumberCanvas height -yNoThe height of the area to be cropped is
destWidthnumberwidth x screen pixel densityNoThe width of the output picture is
destHeightnumberheight x screen pixel densityNoThe height of the output picture is
base64DatastringYesThe image is converted into a base64 type string
successfunctionNoThe interface calls the callback function
failfunctionNoInterface call failed callback function
completefunctionNoThe callback function at the end of the interface call (the call succeeds or fails to execute

object.success callback function

Parameter

Object res

PropertyTypeDescription
tempFilePathstringThe local address of the picture

fileToBase64

fileToBase64(Object object)

will file converted to Base64 Character string

Parameter

Object res

PropertyTypeDescription
urlstringFile address

Return value

string

Base64 String

System

getSystemInfoSync

Supported since base library 1.3.9, iOS version 2.1.23, Android version 2.1.38

getSystemInfoSync()

The synchronous version of ft.getSystemInfo

getSystemInfoAsync

ft.getSystemInfoAsync(Object object)

Get system information asynchronously. Need some WeChat client version support, in the unsupported client, will use synchronization to return.

parameter

Object object

attributetypeDefault valuesRequiredIntroductions
successfunctionnoInterface calls the successful callback function
failfunctionnoInterface calls failed callback functions
completefunctionnoCallback function at the end of an interface call (both successful and unsuccessful calls are executed)

object.success callback

parameter

Object res

attributetypeIntroductionsMinimum version
brandstringEquipment brand1.5.0
modelstringDevice model. New models will show unknown for a while, WeChat will adapt as soon as possible.
pixelRationumberDevice pixel ratio
screenWidthnumberScreen width, in px1.1.0
screenHeightnumberScreen height, in px1.1.0
windowWidthnumberAvailable window width, unit px
windowHeightnumberAvailable window height, in px
statusBarHeightnumberHeight of status bar in px1.9.0
languagestringLanguage of WeChat settings
versionstringWeChat version number
systemstringOperating System and Version
platformstringClient platform
fontSizeSettingnumberUser font size in px. WeChat ClientI - Settings - Universal - Font SizeThe settings in1.5.0
SDKVersionstringClient base library version1.1.0
benchmarkLevelnumberEquipment Performance Level (only Android)。 Values are: -2 or 0 (the device cannot run games), -1 (performance unknown),>= 1 (Device Performance Value, higher the value, better device performance, currently up to less than 50)1.8.0
albumAuthorizedbooleanAllow WeChat to use the Photo Album switch (only iOS Effective)2.6.0
cameraAuthorizedbooleanSwitch that allows WeChat to use the camera2.6.0
locationAuthorizedbooleanAllow WeChat to use location switch2.6.0
microphoneAuthorizedbooleanSwitch allowing WeChat to use microphone2.6.0
notificationAuthorizedbooleanSwitch that allows WeChat notifications2.6.0
notificationAlertAuthorizedbooleanAllow WeChat to notify switches with reminders (only iOS Effective)2.6.0
notificationBadgeAuthorizedbooleanAllow WeChat notifications with marked switches (only iOS Effective)2.6.0
notificationSoundAuthorizedbooleanAllow WeChat to notify switches with sound (only iOS Effective)2.6.0
bluetoothEnabledbooleanBluetooth System Switch2.6.0
locationEnabledbooleanGeographic Location System Switch2.6.0
wifiEnabledbooleanWi-Fi System switch2.6.0
safeAreaObjectA safe area in the positive direction of the vertical screen2.7.0
locationReducedAccuracybooleantrue Represents fuzzy positioning,false For precise positioning, only iOS Support
themestringSystem current theme, with a value oflightordark, global configuration'darkmode': trueCan be obtained when otherwise undefined (Small games not supported)2.11.0
enableDebugbooleanWhether debugging is turned on. Available from the top right menu or ft.setEnableDebug Turn on debugging.2.15.0
bundleIdstringThe bundleId of the host app2.15.0
deviceOrientationstringEquipment direction

safeArea Structure

attributetypeIntroductions
leftnumberUpper left abscissa of security area
rightnumberSecurity area lower right abscissa
topnumberTop-left ordinate of security area
bottomnumberLower right ordinate of security area
widthnumberWidth of security area, unit logical pixels
heightnumberHeight of Safe Area, Unit Logical Pixels

theme Legal value

valueIntroductionsMinimum version
darkDark theme
lightLight color theme

host Structure

attributetypeIntroductions
appIdstringhost app Corresponding appId

deviceOrientation Legal value

valueIntroductionsMinimum version
portraitVertical screen
landscapeHorizontal screen

sample code

Preview with Developer Tool

js
ft.getSystemInfoAsync({
  success (res) {
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
  }
})

getSystemInfo

Supported since base library 1.3.9, iOS version 2.1.23, Android version 2.1.38

getSystemInfo(Object object)

Gets system information.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
successfunctionNoThe callback function for a successful API call
failfunctionNoThe callback function for a failed API call
completefunctionNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)

object.success callback functionParameters

Object res

PropertyTypeDescription
SDKVersionstringBase library version for the WeChat app
runtimeSDKVersionstringmini program SDK version number
brandstringDevice brand
modelstringDevice model
pixelRationumberDevice's pixel ratio
screenWidthnumberScreen width in px
screenHeightnumberScreen height in px
windowWidthnumberAvailable window width in px
windowHeightnumberAvailable window height in px
statusBarHeightnumberStatus bar height in px
languagestringLanguage set in WeChat
versionstringWeChat version
bundleIdstringThe bundleId of the host application
systemstringOperating system and version
platformstringClient platform
inFinChatbooleanIs it in the finchat mini program environment
deviceIdstringEquipment identification

Sample Code

javascript
 ft.getSystemInfo({
  success(res) {
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
  }
})

Updates

getUpdateManager

Supported since base library 1.5.30, iOS version 2.5.6, Android version 2.8.76

ObtainGlobally uniqueThe version update manager for managing Mini Program updates. Update on the Mini Program mechanism, you can seeOperation mechanismDocumentation.

UpdateManager method

UpdateManager.applyUpdate() Force the Mini Program to restart and use the new version. After the new version of the Mini Program has been downloaded (i.e. received onUpdateReady Callback) call.

UpdateManager.onCheckForUpdate(function callback) Monitor the WeChat background request to check the update results event. WeChat automatically checks updates when the Mini Program is cold started, without the developer taking the initiative to trigger.

UpdateManager.onUpdateReady(function callback) Listening Mini Program has a version update event. Active client trigger download (no developer trigger), download success callback

UpdateManager.onUpdateFailed(function callback) Listen for Mini Programs to update failed events. Mini Program has a new version, the client active trigger download (without developer trigger), download failure (may be network reasons, etc.) after the callback

sample code

javascript
const updateManager = ft.getUpdateManager()

updateManager.onCheckForUpdate(function (res) {
  // Callback after requesting new version information
  console.log(res.hasUpdate)
})

updateManager.onUpdateReady(function () {
  ft.showModal({
    title: 'Update tip ',
    content: 'The new version is ready, reboot the app? ' '
    success: function (res) {
      if (res.confirm) {
        // The new version has been downloaded and calls applyUpdate Apply a new version and restart
        updateManager.applyUpdate()
      }
    }
  })
})

updateManager.onUpdateFailed(function () {
  // New version download failed
})

Mini Program

getLaunchOptionsSync

Object ft.getLaunchOptionsSync() Gets the parameters for startup of the Mini Programs. and App.onLaunch The callback parameters of

Return value

Object

Starting parameter

attributetypeIntroductions
pathstringPath to start Mini Programs (Code packet path)

| query | Object | Start the Mini Program query parameter |

| referrerInfo | Object | Source information. From another little program, Official Account message template or App Returns when entering the Mini Program. Otherwise return {}。(See below for attention) |

referrerInfo Structure

attributetypeIntroductions
appIdstringThe appId of Mini Program
extraDataObjectSource Mini Program passed data

getEnterOptionsSync

Object ft.getEnterOptionsSync()

Gets the parameters of this Mini Program when it starts. If the current is a cold start, the return value is identical to the App.onLaunch Consistent with the callback parametersIf this is a hot start, the return value is identical to the App.onShow Consistent

Return value

Object

Starting parameter

attributetypeIntroductions
pathstringPath to start Mini Programs (Code packet path)

| query | Object | Start the Mini Program query parameter |

| referrerInfo | Object | Source information. From another little program, Official Account message template or App Returns when entering the Mini Program. Otherwise return {}。(See below for attention) |

referrerInfo Structure

attributetypeIntroductions
appIdstringThe appId of Mini Program
extraDataObjectSource Mini Program passed data

onPageNotFound

ft.onPageNotFound(function callback)

There are no events on the page that the listening Mini Program wants to open. This event is related to App.onPageNotFound The timing of the pullback was consistent

parameter

function callback

The callback function for the page that the Mini Program opens does not exist

parameter

Object res

attributetypeIntroductions
pathstringNo path to the page (Code packet path)
queryObjectOpen a page that does not exist query parameter
isEntryPagebooleanIs the first page of this launch (for example, from the Share entrance, the first is the developer configuration share page)

Be careful

  • Developers can do page redirection in callbacks, but only in callbacksynchronizationProcessing, asynchronous processing such as setTimeout Asynchronous execution) is invalid.
  • If the developer does not call ft.onPageNotFound Binding listening, no declaration App.onPageNotFound, When the jump page does not exist, will push the WeChat client native page there is no prompt page.
  • If the callback is redirected to another page that does not exist, the original page of WeChat client will be pushed into the page that is not there and there will be no second callback.

onError

ft.onError(function callback)

Listens for Mini Program error events. Such as a script error or API Call error, etc. This event is related to App.onError The callback timing of the.

parameter

function callback

Callback function for Mini Program error event

parameter

string error

Error message, including stack

onAppShow

ft.onAppShow(function callback)

Listen to the Mini Program cut foreground events. This event is related to App.onShow The callback parameters of

parameter

function callback

Callback Function for Mini Programs to Cut Foreground Events

parameter

Object res

attributetypeIntroductions
pathstringMini Programs cut the foreground path (Code packet path)
queryObjectMini Program cut the front desk query parameter
referrerInfoObjectSource information. From another little program, Official Account message template or App Returns when entering the Mini Program. Otherwise return {}。(See below for attention)

referrerInfo Structure

attributetypeIntroductions
appIdstringThe appId of Mini Program
extraDataObjectSource Mini Program passed data

Be careful

Partial Version NoreferrerInfoWill return when undefinedRecommended for use options.referrerInfo && options.referrerInfo.appId To judge.

onAppHide

ft.onAppHide(function callback)

Listen to the Mini Program cut background events. This event is related to App.onHide The timing of the pullback was consistent.

parameter

function callback

Callback Function for Background Events

offPageNotFound

ft.offPageNotFound(function callback)

The page to be opened by the unlisten Mini Program does not have an event

parameter

function callback

The callback function for the page that the Mini Program opens does not exist

offError

ft.offError(function callback)

Cancels listening for Mini Program error events

parameter

function callback

Callback function for Mini Program error event

offAppShow

ft.offAppShow(function callback)

Cancel the monitor Mini Program to cut the foreground event

parameter

function callback

Callback Function for Mini Programs to Cut Foreground Events

offAppHide

ft.offAppHide(function callback)

Cancel listening Mini Program to cut background event

parameter

function callback

Callback Function for Background Events

onThemeChange

ft.onThemeChange(function callback)

Listen for system topic change events

parameter

function callback

Callback function for the system topic change event

onUnhandledRejection

ft.onUnhandledRejection(function callback)

Listen for unprocessed Promise rejection events

parameter

function callback

Callback function for an unhandled Promise rejection event

offUnhandledRejection

ft.offUnhandledRejection(function callback)

Cancel listening for unprocessed Promise rejection events

parameter

function callback

onUnhandledRejection Incoming callback function. If this argument is not passed, all listening functions are removed.

offThemeChange

ft.offThemeChange(function callback)

Cancels listening for system topic change events

parameter

function callback

onThemeChange The callback function passed in. If this parameter is not passed, all listener functions are removed.

debugging

setEnableDebug

ft.setEnableDebug(Object object)

Sets whether the debug switch is turned on. This switch also works for the official version

parameter

Object object

attributetypeDefault valuesRequiredIntroductions
enableDebugbooleanyesTurn on debugging
successfunctionnoInterface calls the successful callback function
failfunctionnoInterface calls failed callback functions
completefunctionnoCallback function at the end of an interface call (both successful and unsuccessful calls are executed)

sample code

javascript
// Turn on debugging
ft.setEnableDebug({
  enableDebug: true
})

// Close debugging
ft.setEnableDebug({
  enableDebug: false
})

Tips

  • In the official version to open debugging there is a way that is first in the development version or the experience version of the open debugging, and then cut to the formal version can see vConsole.

console

Prints logs to the debugging console. The "console" is a global object and can be accessed directly. In the WeChat app, logs are output to vConsole.

console.debug()

Prints the "debug" log to the debugging panel.

console.error()

Prints the "error" log to the debugging panel.

console.group()

Creates a new group in the debugging panel.

console.groupEnd()

Ends a group created by console.group.

console.info()

Prints the "info" log to the debugging panel.

console.log()

Prints the "log" log to the debugging panel.

console.warn()

Prints the "warn" log to the debugging panel.

LogManager

Log manager instance

LogManager.debug()

write debug journal

LogManager.info()

write info journal

LogManager.log()

write log journal

LogManager.warn()

write warn journal

RealtimeLogManager

Real - time log manager instance

RealtimeLogManager.info()

write info Logging is not supported in plugins

RealtimeLogManager.warn()

write warn Logging is not supported in plugins

RealtimeLogManager.error()

write error Logging is not supported in plugins

RealtimeLogManager.setFilterMsg(string msg)

Set filter keywords, temporarily do not support the use of

RealtimeLogManager.addFilterMsg(string msg)

Add filter keywords, temporarily not supported in plugin use

Account information

getAccountInfoSync

Gets the current account information. Online Mini Program version number is only available in the official version of the Mini Program, development version and experience version can not be obtained

Return value

Object object

attributetypeDefault valuesRequiredIntroductions
miniProgramObjectyesMini Program account information

Object miniProgram

attributetypeIntroductions
appIdstringMini Program appId
envVersionstringMini Program version