${API}.${method}.${param}.${options} or ${component}.${attribute}.${option} to call.Parameter | Description |
${API} | API name. |
${method} | Call method. Valid values: return, success, object, callback. |
${param} | Parameter or return value. |
${options} | Optional values of the parameter. |
${component} | Component name. |
${attribute} | Component property. |
${option} | Optional value of the component property. |
wx.canIUse('openBluetoothAdapter')wx.canIUse('getSystemInfoSync.return.screenWidth')wx.canIUse('getSystemInfo.success.screenWidth')wx.canIUse('showToast.object.image')wx.canIUse('onCompassChange.callback.direction')wx.canIUse('request.object.method.GET')wx.canIUse('live-player')wx.canIUse('text.selectable')wx.canIUse('button.open-type.contact')
const base64 = 'CxYh'const arrayBuffer = wx.base64ToArrayBuffer(base64)
const arrayBuffer = new Uint8Array([11, 22, 33])const base64 = wx.arrayBufferToBase64(arrayBuffer)
Property | Type | Default value | Required | Description |
success | Function | - | False | Callback function for successful API calls. |
fail | Function | - | False | Callback function for failed API calls. |
complete | Function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
brand | String | Device brand. |
model | String | Device model. |
pixelRatio | Number | Device pixel ratio. |
screenWidth | Number | Screen width in px. |
screenHeight | Number | Screen height in px. |
windowWidth | Number | Available window width in px. |
windowHeight | Number | Available window height in px. |
statusBarHeight | Number | Status bar height in px. |
language | String | Language. |
version | String | Version number. |
system | String | Operating system and version. |
platform | String | Client platform. Valid values: iOS: including iPhone and iPad Android devtools: TCSAS developer tools |
fontSizeSetting | number | User font size in px. |
SDKVersion | String | Base library version of the client. |
AppPlatform | String | App platform. |
safeArea | Object | Safe area in portrait mode. |
theme | String | Current system theme. Value: Light or dark.Only available if"darkmode":true Otherwise, it is undefined. |
Property | Type | Description |
left | Number | X-coordinate of the top-left corner of the safe area. |
right | Number | X-coordinate of the bottom-right corner of the safe area. |
top | Number | Y-coordinate of the top-left corner of the safe area. |
bottom | Number | Y-coordinate of the bottom-right corner of the safe area. |
width | Number | Width of the safe area in logical pixels. |
height | Number | Height of the safe area in logical pixels. |
wx.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)}})
try {const res = wx.getSystemInfoSync()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)} catch (e) {// Do something when catch error}
Property | Type | Description |
brand | String | Device brand. |
model | String | Device model. |
pixelRatio | Number | Device pixel ratio. |
screenWidth | Number | Screen width in px. |
screenHeight | Number | Screen height in px. |
windowWidth | Number | Available window width in px. |
windowHeight | Number | Available window height in px. |
statusBarHeight | Number | Status bar height in px. |
language | String | Language. |
version | String | Version number. |
system | String | Operating system and version. |
platform | String | Client platform. Valid values: iOS: including iPhone and iPad Android devtools: TCSAS developer tools |
fontSizeSetting | number | User font size in px. |
AppPlatform | String | App platform. |
safeArea | Object | Safe area in portrait mode. |
theme | String | Current system theme. Value: Light or dark.Only available if"darkmode":true Otherwise, it is undefined. (Not supported in mini games) |
Property | Type | Description |
left | Number | X-coordinate of the top-left corner of the safe area. |
right | Number | X-coordinate of the bottom-right corner of the safe area. |
top | Number | Y-coordinate of the top-left corner of the safe area. |
bottom | Number | Y-coordinate of the bottom-right corner of the safe area. |
width | Number | Width of the safe area in logical pixels. |
height | Number | Height of the safe area in logical pixels. |
wx.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)}})
try {const res = wx.getSystemInfoSync()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)} catch (e) {// Do something when catch error}
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
brand | string | Device brand. |
model | string | Device model. New models may show as Unknown for a while until adapted. |
pixelRatio | number | Device pixel ratio. |
screenWidth | number | Screen width in px. |
screenHeight | number | Screen height in px. |
windowWidth | number | Available window width in px. |
windowHeight | number | Available window height in px. |
statusBarHeight | number | Task status bar height in px. |
language | string | Language set in the app. |
version | string | App version number. |
system | string | Operating system and version. |
platform | string | Client platform. Valid values: iOS: including iPhone and iPad Android devtools: IDE |
fontSizeSetting | number | User font size in px. |
SDKVersion | string | Base library version of the client. |
safeArea | object | Safe area in portrait mode. Some devices do not have a safe area concept and will not return the safeArea field. Developers need to handle this compatibility. For return values, see the table Return values of safeArea |
theme | string | The current system theme. The value can only be obtained when darkmode: true is set in global configuration. Otherwise, it is undefined (not supported in mini games). Valid values: Light: bright mode Dark: dark mode |
Structural property | Type | Description |
left | number | X-coordinate of the top-left corner of the safe area. |
right | number | X-coordinate of the bottom-right corner of the safe area. |
top | number | Y-coordinate of the top-left corner of the safe area. |
bottom | number | Y-coordinate of the bottom-right corner of the safe area. |
width | number | Width of the safe area in logical pixels. |
height | number | Height of the safe area in logical pixels. |
wx.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)}})
Property | Type | Description |
pixelRatio | number | Device pixel ratio. |
screenWidth | number | Screen width in px. |
screenHeight | number | Screen height in px. |
windowWidth | number | Available window width in px. |
windowHeight | number | Available window height in px. |
statusBarHeight | number | Status bar height in px. |
safeArea | object | Safe area in portrait mode. Some devices do not have a safe area concept and will not return the safeArea field. Developers need to handle this compatibility. |
screenTop | number | The y-coordinate of the top edge of the window. |
Structural property | Type | Description |
left | number | X-coordinate of the top-left corner of the safe area. |
right | number | X-coordinate of the bottom-right corner of the safe area. |
top | number | Y-coordinate of the top-left corner of the safe area. |
bottom | number | Y-coordinate of the bottom-right corner of the safe area. |
width | number | Width of the safe area in logical pixels. |
height | number | Height of the safe area in logical pixels. |
const windowInfo = wx.getWindowInfo()console.log(windowInfo.pixelRatio)console.log(windowInfo.screenWidth)console.log(windowInfo.screenHeight)console.log(windowInfo.windowWidth)console.log(windowInfo.windowHeight)console.log(windowInfo.statusBarHeight)console.log(windowInfo.safeArea)console.log(windowInfo.screenTop)
Property | Type | Description |
bluetoothEnabled | boolean | Bluetooth permission. |
locationEnabled | boolean | Location permission. |
wifiEnabled | boolean | Wi-Fi permission. |
deviceOrientation | string | Device orientation. Valid values: Portrait: Portrait mode Landscape: Landscape mode |
const systemSetting = wx.getSystemSetting()console.log(systemSetting.bluetoothEnabled)console.log(systemSetting.deviceOrientation)console.log(systemSetting.locationEnabled)console.log(systemSetting.wifiEnabled)
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.openSystemBluetoothSetting({success (res) {console.log(res)}})
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.openAppAuthorizeSetting({success (res) {console.log(res)}})
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.getRendererUserAgent().then(userAgent => console.log(userAgent))wx.getRendererUserAgent({success(res) {console.log(res.userAgent)}})
Property | Type | Description |
abi | string | Host app's binary interface type (Android only). |
deviceAbi | string | Device’s binary interface type (Android only). |
benchmarkLevel | number | Device performance level (Android only). Valid values: -2 or 0: Mini games are not supported on the device. -1: Performance unknown. >=1: Device performance value (the max value is currently less than 50). The higher the value, the better the device performance. |
brand | string | Device brand. |
model | string | Device model. New models may show as Unknown for a while until adapted. |
system | string | Operating system and version. |
platform | string | Client platform. |
cpuType | string | Device CPU model (supported on Android only).The GPU model can be obtained using WebGLRenderingContext.getExtension('WEBGL_debug_renderer_info'). |
memorySize | string | Device memory size in MB. |
const deviceInfo = wx.getDeviceInfo()console.log(deviceInfo.abi)console.log(deviceInfo.benchmarkLevel)console.log(deviceInfo.brand)console.log(deviceInfo.model)console.log(deviceInfo.platform)console.log(deviceInfo.system)
Property | Type | Description |
SDKVersion | string | Base library version of the host client. |
enableDebug | boolean | Whether debugging has been enabled. You can open the menu in the upper right corner, tap Enable debugging or using wx.setEnableDebug to enable debugging. |
host | Object | The host environment where the current mini program is running. |
language | string | Language set on the host client. |
version | string | Host client version number. |
theme | string | The current system theme. Valid values: light: Bright mode, or dark: Dark mode. The value can only be obtained when "darkmode":true is set in global configuration. Otherwise, it is undefined (not supported in mini games). |
const appBaseInfo = wx.getAppBaseInfo()console.log(appBaseInfo.SDKVersion)console.log(appBaseInfo.enableDebug)console.log(appBaseInfo.host)console.log(appBaseInfo.language)console.log(appBaseInfo.version)console.log(appBaseInfo.theme)
Property | Type | Description |
albumAuthorized | 'authorized'/'denied'/'not determined' | Gets the album permission info of the host client. (iOS only). |
bluetoothAuthorized | 'authorized'/'denied'/'not determined' | Gets the Bluetooth permission info of the host client. (iOS only). |
cameraAuthorized | 'authorized'/'denied'/'not determined' | Gets the camera permission info of the host client. |
locationAuthorized | 'authorized'/'denied'/'not determined' | Gets the location permission info of the host client. |
locationReducedAccuracy | boolean | Location accuracy. true indicates approximate location, while false indicates precise location (iOS only). |
microphoneAuthorized | 'authorized'/'denied'/'not determined' | Gets the microphone permission info of the host client. |
notificationAuthorized | 'authorized'/'denied'/'not determined' | Gets the notification permission info of the host client. |
notificationAlertAuthorized | 'authorized'/'denied'/'not determined' | Gets the reminder permission info of the host client. (iOS only). |
notificationBadgeAuthorized | 'authorized'/'denied'/'not determined' | Gets the notification badge permission info of the host client. (iOS only). |
notificationSoundAuthorized | 'authorized'/'denied'/'not determined' | Gets the sound notification permission info of the host client. (iOS only). |
phoneCalendarAuthorized | 'authorized'/'denied'/'not determined' | Gets the calendar permission info of the host client. |
const appAuthorizeSetting = wx.getAppAuthorizeSetting()console.log(appAuthorizeSetting.albumAuthorized)console.log(appAuthorizeSetting.bluetoothAuthorized)console.log(appAuthorizeSetting.cameraAuthorized)console.log(appAuthorizeSetting.locationAuthorized)console.log(appAuthorizeSetting.locationReducedAccuracy)console.log(appAuthorizeSetting.microphoneAuthorized)console.log(appAuthorizeSetting.notificationAlertAuthorized)console.log(appAuthorizeSetting.notificationAuthorized)console.log(appAuthorizeSetting.notificationBadgeAuthorized)console.log(appAuthorizeSetting.notificationSoundAuthorized)console.log(appAuthorizeSetting.phoneCalendarAuthorized)
Property | Type | Description |
miniProgram | Object | the mini program account information |
Structural property | Type | Description |
appId | string | mini program appId |
envVersion | string | mini program version. valid values: develop: development version trial: preview version release: released version |
version | string | the online mini program version No. |
onUpdateReady callback).Property | Type | Description |
hasUpdate | Boolean | Checks if a new version is available. |
const updateManager = wx.getUpdateManager()updateManager.onCheckForUpdate(function (res) {// Callback after requesting new version informationconsole.log(res.hasUpdate)})updateManager.onUpdateReady(function () {wx.showModal({title: 'Update prompt',content: 'A new version is ready. Would you like to restart the application?success(res) {if (res.confirm) {// The new version has been downloaded. Call applyUpdate to apply the new version and restart.updateManager.applyUpdate()}}})})updateManager.onUpdateFailed(function () {// New version download failed})
referrerInfo may return undefined.It is recommended to use options.referrerInfo && options.referrerInfo.appId.Property | Type | Description |
path | String | The path used to launch the mini program. (for mini programs only). |
scene | Number | The scene value when the mini program is launched, default is 1001. |
query | Object | The query parameters used to launch the mini program. |
referrerInfo | Object | The referrer of the information, returned when entering a mini program from another mini program or an app. Otherwise, it returns {}. |
forwardMaterials | Array.<Object> | An array of opened file information. |
extendData | String | The parameters passed when the SDK opens the mini-program |
Property | Type | Description |
appId | String | The referrer's AppID for the mini program or app. |
extraData | Object | Data passed from the referrer of the mini program. |
[[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:@"mpbz0uqwzddj5zbt" scene:TMAEntrySceneNone firstPage:nil paramsStr:@"a=1&b=2" parentVC:self completion:^(NSError * _Nullable err) {}];
MiniStartLinkOptions miniStartOptions = new MiniStartLinkOptions(); miniStartOptions.params = (String) options.get("params");public static void startMiniApp(Activity activity, String appId, MiniStartOptions options) { startMiniApp(activity, appId, 1001, 0, options);}
Property | Type | Description |
type | string | The MIME type of the file. |
name | Object | File name. |
path | string | File path. |
size | number | File size. |
referrerInfo returnedProperty | Type | Description |
1037 | Opens the mini program from another mini program | The referrer of the mini program. |
1038 | Returns from another mini program | The referrer of the mini program. |
referrerInfo may return undefinedIt is recommended to use options.referrerInfo && options.referrerInfo.appId.Property | Type | Description |
path | string | The path used to launch the mini program (code package path). (for mini programs only). |
scene | number | The scene value used to launch the mini program. |
query | Object | The query parameters used to launch the mini program. |
shareTicket | string | shareTicket |
referrerInfo | Object | The information of the referrer. Returned when the mini program is accessed from another mini program or an app. Otherwise, {} is returned. For details, see the note above the table. |
forwardMaterials | Array.<Object> | An array of opened file information. |
extendData | String | The parameters passed when the SDK opens the mini-program |
Property | Type | Description |
appId | String | The referrer's AppID for the mini program or app. |
extraData | Object | Data passed from the referrer of the mini program. |
Property | Type | Description |
type | String | The MIME type of the file. |
name | Object | File name. |
path | String | File path, or URL if using web-view component. |
size | Number | File size. |
Property | Type | Description |
1037 | Opens the mini program from another mini program | The referrer of the mini program. |
1038 | Returns from another mini program | The referrer of the mini program. |
Property | Valid values and description | Type | Description |
theme | Dark: Dark theme Light: Light theme | String | The current theme of the system, with the value is light or dark. |
const listener = function (res) { console.log(res) }wx.onThemeChange(listener)wx.offThemeChange(listener) // Must pass the same function object used in onThemeChange
Property | Type | Description |
path | string | The path of the non-existent page (code package path). |
query | Object | Query parameter for opening a non-existent page. |
isEntryPage | boolean | Whether it is the first page of this launch (for example, when entering from a shared link, the first page is the share page configured by the developer). |
const listener = function (res) { console.log(res) }wx.onPageNotFound(listener)wx.offPageNotFound(listener) // Must pass the same function object used in onPageNotFound
options.referrerInfo && options.referrerInfo.appId.Property | Type | Description |
path | string | The path used to launch the mini program (code package path). |
scene | number | The scene value used to launch the mini program. |
query | Object | The query parameters used to launch the mini program. |
shareTicket | string | shareTicket |
referrerInfo | Object | The information of the referrer. Returned when the mini program is accessed from another mini program or an app. Otherwise, {} is returned. For details, see the note above the table. |
forwardMaterials | Array.<Object> | An array of opened file information. |
Property | Type | Description |
appId | string | The referrer's AppID for the mini program or app. |
extraData | Object | Data passed from the referrer of the mini program. |
Property | Type | Description |
type | String | The MIME type of the file. |
name | Object | File name. |
path | String | File path, or URL if using web-view component. |
size | Number | File size. |
Scene value | Scene | Description |
1037 | Opens the mini program from another mini program | The referrer of the mini program. |
1038 | Returns from another mini program | The referrer of the mini program. |
const listener = function (res) { console.log(res) }wx.onAppShow(listener)wx.offAppShow(listener) // Must pass the same function object used in onAppShow
const listener = function (res) { console.log(res) }wx.onAppHide(listener)wx.offAppHide(listener) // Must pass the same function object used in onAppHide
Property | Type | Description |
scene | number | Scene value. |
query | Object | Query parameter. |
shareTicket | string | shareTicket |
referrerInfo | Object | The information of the referrer. Returned when the mini program is accessed from another mini program or an app. |
Property | Type | Description |
appId | string | The referrer's AppID for the mini program or app. |
extraData | Object | Data passed from the referrer of the mini program. |
const listener = function (res) { console.log(res) }wx.onShow(listener)wx.offShow(listener) // Must pass the same function object used in onShow
const listener = function (res) { console.log(res) }wx.onHide(listener)wx.offHide(listener) // Must pass the same function object used in onHide
Property | Type | Description |
reason | string | Rejection reason, typically an Error object. |
promise | Promise.<any> | The rejected Promise object. |
const listener = function (res) { console.log(res) }wx.onUnhandledRejection(listener)wx.offUnhandledRejection(listener) // Must pass the same function object used in onUnhandledRejection
Property | Type | Default value | Required | Description |
enableDebug | boolean | - | True | Whether to enable debugging. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
// Enable debuggingwx.setEnableDebug({enableDebug: true})// Disable debuggingwx.setEnableDebug({enableDebug: false})
// For the mini programconst logger = wx.getRealtimeLogManager()logger.info({str: 'hello world'}, 'info log', 100, [1, 2, 3])logger.error({str: 'hello world'}, 'error log', 100, [1, 2, 3])logger.warn({str: 'hello world'}, 'warn log', 100, [1, 2, 3])// For the plugin. Supported on the basic library 2.16.0 and later versions, and only reporting in the new key-value format is allowed.const logManager = wx.getRealtimeLogManager()const logger = logManager.tag('plugin-log1')logger.info('key1', 'value1')logger.error('key2', {str: 'value2'})logger.warn('key3', 'value3')
Property | Type | Default value | Required | Description |
level | number | 0 | False | The valid values are 0 and1, where 0 indicates the calls of lifecycle functions of App and Page, , as well as function calls under the namespace, will be logged. A value of 1 means they will not be logged. The default value is 0. |
const logger = wx.getLogManager({level: 1})logger.log({str: 'hello world'}, 'basic log', 100, [1, 2, 3])logger.info({str: 'hello world'}, 'info log', 100, [1, 2, 3])logger.debug({str: 'hello world'}, 'debug log', 100, [1, 2, 3])logger.warn({str: 'hello world'}, 'warn log', 100, [1, 2, 3])
<Button> component’s open-type="feedback" feature to upload the printed logs. Developers can view the feedback on the User feedback page on the mini program management backend.App and Page, , and calls of functions under the namespace into the log.Property | Type | Description |
size | number | The space already used in the current cache in bytes. |
maxSize | number | The maximum available space in the current cache in bytes. |
logCount | number | The number of log entries in the current cache. |
maxLogCount | number | The maximum number of log entries that can be stored in the current cache. |
Property | Type | Default value | Required | Description |
packageType | string | 'normal' | False | Subpackage type. The name field becomes invalid if you enter "workers" for this property. |
name | string | | True | Subpackage name. You can enter name or root. In an independent subpackage, __GAME__ indicates loading the main package. |
success | function | | True | Callback function for successful subpackage loading. |
fail | function | | True | Callback function for failed subpackage loading. |
complete | function | | True | Callback function executed after the subpackage loading ends (regardless of success or failure). |
// Configure workers as a subpackage in app.json / game.json first{"workers": {"path": "myWorkersFolder","isSubpackage": true // true means the worker is packaged as a subpackage Default value: False. If false, it is equivalent to { "workers": "myWorkersFolder" }}}
// Call wx.preDownloadSubpackage to download the worker subpackage. Only after the download is successful can you create the workervar task = wx.preDownloadSubpackage({packageType: "workers",success(res) {console.log("load worker success", res)wx.createWorker("myWorkersFolder/request/index.js") // Create worker. If the worker subpackage is not fully downloaded, calling createWorker will result in an error.},fail(res) {console.log("load worker fail", res)}})task.onProgressUpdate(res => {console.log(res.progress) // Listen to download progress using onProgressUpdateconsole.log(res.totalBytesWritten)console.log(res.totalBytesExpectedToWrite)})
// Configure the subpackage in app.json / game.json first{"subPackages": [{"name": "ModuleA","root": "/ModuleA/"}]}
var task = wx.preDownloadSubpackage({name: "ModuleA",success(res) {console.log("load subpackage success", res)// Execute the subpackage codewx.loadSubpackage({name: "ModuleA",success(res) {console.log(res)},})},fail(res) {console.log("load subpackage fail", res)}})task.onProgressUpdate(res => {console.log(res.progress) // Listen to download progress using onProgressUpdateconsole.log(res.totalBytesWritten)console.log(res.totalBytesExpectedToWrite)})
Property | Type | Description |
progress | number | Subpackage download progress in percentage. |
totalBytesWritten | number | The downloaded data length in bytes. |
totalBytesExpectedToWrite | number | The total length of data expected to be downloaded, in bytes. |
Property | Type | Default value | Required | Description |
packageType | string | 'normal' | False | Subpackage type. The name field becomes invalid if you enter "workers" for this property. |
name | string | | True | Subpackage name. You can enter name or root. In an independent subpackage, __GAME__ indicates loading the main package. |
success | function | | True | Callback function for successful subpackage loading. |
fail | function | | True | Callback function for failed subpackage loading. |
complete | function | | True | Callback function executed after the subpackage loading ends (regardless of success or failure). |
Property | Type | Description |
progress | number | Subpackage download progress in percentage. |
totalBytesWritten | number | The length of data that has been downloaded, in bytes. |
totalBytesExpectedToWrite | number | The total length of data expected to be downloaded, in bytes. |
Feedback