tencent cloud

Feedback

Fundamentals

Last updated: 2024-11-21 18:41:54

    canIUse

    This API is called using Boolean wx.canIUse(string schema).
    Feature description:Determines whether the APIs, callback functions, parameters, and components of the mini program are supported in the current version.
    Parameter and description:String schema
    Use ${API}.${method}.${param}.${options}  or  ${component}.${attribute}.${option} to call.
    Description:
    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
    Return value: Boolean, indicating whether the feature is available in the current version.
    Example:
    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')

    env

    This API is called using wx.env.
    Feature description:Environment variables.
    Parameter and description:string USER_DATA_PATH, the user directory path in the file system (local path).

    base64ToArrayBuffer

    This API is called using ArrayBuffer wx.base64ToArrayBuffer(string base64).
    Feature description:Converts a Base64 string into an ArrayBuffer object.
    Parameter and description:string base64, the Base64 string to be converted into an ArrayBuffer object.
    Return value:An ArrayBuffer object.
    Example:
    const base64 = 'CxYh'
    const arrayBuffer = wx.base64ToArrayBuffer(base64)

    arrayBufferToBase64

    This API is called using string wx.arrayBufferToBase64(ArrayBuffer arrayBuffer).
    Feature description:Converts an ArrayBuffer object into a Base64 string.
    Parameter and description:The ArrayBuffer object to be converted into a Base64 string.
    Return value:string, a Base64 string.
    Example:
    const arrayBuffer = new Uint8Array([11, 22, 33])
    const base64 = wx.arrayBufferToBase64(arrayBuffer)

    System

    getSystemInfo

    This API is called using wx.getUserInfo(Object object).
    Feature description:Gets system information.
    Parameter and description:Object Object.
    Property
    Type
    Default value
    ‍Required
    Description
    success
    Function
    -
    No
    Callback function for successful API calls
    fail
    Function
    -
    No
    Callback function for failed API calls
    complete
    Function
    -
    No
    Callback function executed when the API call is complete (regardless of success or failure)
    Res callback result of Object.success
    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
    OS and version
    platform
    String
    Client platform. Valid values:
    iOS: including iPhone and iPad
    Android
    devtools: TCMPP 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.
    res.safeArea structure:
    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
    Example:
    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
    }

    getSystemInfoSync

    This API is called using Object wx.getSystemInfoSync().
    Feature description: wx.getSystemInfo.
    Res callback result of Object.success
    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
    OS and version
    platform
    String
    Client platform. Valid values:
    iOS: including iPhone and iPad
    Android
    devtools: TCMPP 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.
    res.safeArea structure:
    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
    Example:
    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
    }
    

    getSystemInfoAsync

    This API is called using wx.getSystemInfoAsync(Object object).
    Feature description:Gets system information asynchronously. This feature is enabled only on certain versions of host client. On unsupported clients, system information is got synchronously.
    Parameter and description:Object object.
    Property
    Type
    Default value
    ‍Required
    Description
    success
    function
    -
    No
    Callback function for successful API calls
    fail
    function
    -
    No
    Callback function for failed API calls
    complete
    function
    -
    No
    Callback function executed when the API call is complete (regardless of success or failure)
    Parameters for object.success callback function:Object res
    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
    OS 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
    Return values of safeArea
    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
    Vertical coordinate of the lower 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
    Example:
    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)
    }
    })

    getWindowInfo

    This API is called using Object wx.getWindowInfo().
    Feature description:Gets window information.
    Parameter and description:Object.
    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
    Return values of safeArea
    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
    Vertical coordinate of the lower 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
    Example:
    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)

    getSystemSetting

    This API is called using Object wx.getSystemSetting().
    Feature description:Gets device settings.
    Parameter and description:Object.
    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
    Example:
    const systemSetting = wx.getSystemSetting()
    
    console.log(systemSetting.bluetoothEnabled)
    console.log(systemSetting.deviceOrientation)
    console.log(systemSetting.locationEnabled)
    console.log(systemSetting.wifiEnabled)

    openSystemBluetoothSetting

    This API is called using wx.openSystemBluetoothSetting(Object object).
    Feature description:Redirects to the system’s Bluetooth settings page. Only supported on Android.
    Parameter and description:Object object.
    Property
    Type
    Default value
    ‍Required
    Description
    success
    function
    -
    No
    Callback function for successful API calls
    fail
    function
    -
    No
    Callback function for failed API calls
    complete
    function
    -
    No
    Callback function executed when the API call is complete (regardless of success or failure)
    Example:
    wx.openSystemBluetoothSetting({
    success (res) {
    console.log(res)
    }
    })

    openAppAuthorizeSetting

    This API is called using wx.openAppAuthorizeSetting(Object object).
    Feature description:Redirects to the system host client's authorization management page.
    Parameter and description:Object object.
    Property
    Type
    Default value
    ‍Required
    Description
    success
    function
    -
    No
    Callback function for successful API calls
    fail
    function
    -
    No
    Callback function for failed API calls
    complete
    function
    -
    No
    Callback function executed when the API call is complete (regardless of success or failure)
    Example:
    wx.openAppAuthorizeSetting({
    success (res) {
    console.log(res)
    }
    })

    getRendererUserAgent

    This API is called using Promise wx.getRendererUserAgent(Object object).
    Feature description:Gets the UserAgent of the web-view container where the mini program is running.
    Parameter and description:Object object.
    Property
    Type
    Default value
    ‍Required
    Description
    success
    function
    -
    No
    Callback function for successful API calls
    fail
    function
    -
    No
    Callback function for failed API calls
    complete
    function
    -
    No
    Callback function executed when the API call is complete (regardless of success or failure)
    Parameters for object.success callback function:string userAgent, UserAgent.
    Return value:Promise.<string>.
    Example:
    wx.getRendererUserAgent().then(userAgent => console.log(userAgent))
    wx.getRendererUserAgent({
    success(res) {
    console.log(res.userAgent)
    }
    })

    getDeviceInfo

    This API is called using Object wx.getDeviceInfo().
    Feature description:Gets the basic information of the device.
    Return value:Object.
    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
    OS 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').
    menorySize
    string
    Device memory size in MB
    Example:
    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)

    getAppBaseInfo

    This API is called using Object wx.getAppBaseInfo().
    Feature description:Gets basic information of the host client.
    Parameter and description:Object.
    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, click Enable debugging or using setEnableDebug to enable debugging.
    host
    Object
    The host environment where the current mini program is running.
    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).
    Example:
    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)

    getAppAuthorizeSetting

    This API is called using Object wx.getAppAuthorizeSetting().
    Feature description:Gets permission info of the host client.
    Parameter and description:Object.
    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 (only available on iOS).
    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.
    Example:
    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)

    Update

    getUpdateManager

    This API is called using UpdateManager wx.getUpdateManager().
    Feature description: Gets the globally unique version update manager, used for managing the mini program updates.
    Return value: UpdateManager object.

    UpdateManager

    .applyUpdate

    This method is called using UpdateManager.applyUpdate().
    Feature description:Forces the mini program to restart and use the new version. It is called after the new version of the mini program is downloaded (i.e. upon receipt of the onUpdateReady callback).

    .onCheckForUpdate

    This method is called using UpdateManager.onCheckForUpdate(function listener).
    Feature description:Requests the backend to check for updates. This process is automatically triggered during the mini program's cold start, so developers don't need to initiate it manually.
    Parameter and description:A callback function for the event that requests the backend to check for updates.
    Property
    Type
    Description
    hasUpdate
    Boolean
    Checks if a new version is available

    .onUpdateFailed

    This method is called using UpdateManager.onUpdateFailed(function listener).
    Feature description:Checks mini program update failures. When a new version of the mini program is available, the client automatically initiates the download (no developer action required). If the download fails (possibly due to network issues), this callback is triggered.
    Parameter and description:A callback function for the event when the mini program update fails.

    .onUpdateReady

    This method is called using UpdateManager.onUpdateReady(function listener).
    Feature description:Checks mini program updates. The client initiates the download (no developer triggering required). Once the download is successful, this callback is triggered.
    Parameter and description:A callback function for the event when a new version of the mini program is available.
    Example:
    const updateManager = wx.getUpdateManager()
    
    updateManager.onCheckForUpdate(function (res) {
    // Callback upon requesting new version information
    console.log(res.hasUpdate)
    })
    
    updateManager.onUpdateReady(function () {
    wx.showModal({
    title: 'Update prompt',
    content: 'The new version is ready. Do you want 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
    })

    Mini program

    Lifecycle

    getLaunchOptionsSync

    This API is called using Object wx.getLaunchOptionsSync().
    Note:
    In some versions, referrerInfo may return undefined if not present. It is recommended to check using options.referrerInfo &amp;&amp; options.referrerInfo.appId.
    Feature description:Gets the parameters when the mini program starts up.
    Return value:Object, startup parameters.
    Property
    Type
    Description
    path
    String
    The path of the mini program startup
    scene
    Number
    Scene value for starting up the mini program. Default value: 1001
    query
    Object
    Query parameter for starting up 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
    Structure of referrerInfo
    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
    Note:
    extraData is the extended parameter passed from the client when the mini program starts up.
    For iOS: It is the paramsStr parameter passed in the startUMiniAppWithAppID method.
    [[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:@"mpbz0uqwzddj5zbt" scene:TMAEntrySceneNone firstPage:nil paramsStr:@"a=1&amp;b=2" parentVC:self completion:^(NSError * _Nullable err) {
    
    }];
    For Android: It is the params field of the MiniStartLinkOptions object.
    
    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);
    }
    
    
    Structure of forwardMaterials
    Property
    Type
    Description
    type
    string
    The MIME type of the file
    name
    Object
    File name
    path
    string
    File path
    size
    number
    File size
    Scenes with valid referrerInfo returned
    Property
    Type
    Description
    The referrer of the app
    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

    getEnterOptionsSync

    This API is called using Object wx.getEnterOptionsSync().
    Note:
    In some versions, referrerInfo may return undefined if not present. It is recommended to check using options.referrerInfo &amp;&amp; options.referrerInfo.appId.
    Feature description:Gets the parameters when the mini program starts up. If it is a cold start, the return value is consistent with the callback parameter of App.onLaunch . If it is a hot start, the return value is consistent with  App.onShow .
    Return value:Object
    Property
    Type
    Description
    path
    string
    The path of the mini program startup (code package path)
    scene
    number
    The scene value of the mini program startup
    query
    Object
    The query parameter of the mini program startup
    shareTicket
    string
    shareTicket
    referrerInfo
    Object
    The referrer of the information. Returned when entering the mini program from another mini program, WeChat official account, or an app. Otherwise, {} is returned. For details, see the notes above the table.
    forwardMaterials
    Array.<Object>
    An array of opened file information
    Structure of referrerInfo
    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
    Structure of forwardMaterials
    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
    Scenes with valid referrerInfo returned
    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

    App-level events

    onError

    This API is called using wx.onError(function callback).
    Feature description:Listens for mini program error events, such as script errors or API call failures.
    Parameter and description:A callback function for mini program error events.
    Response parameters: string error, error information, including the stack.

    offError

    This API is called using wx.offError(function callback).
    Feature description:Cancels listening for mini program errors
    Parameter and description:A callback function for mini program error events.

    onThemeChange

    This API is called using wx.onThemeChange(function listener).
    Note:
    This event is triggered only when darkmode:true is set in the global configuration.
    Feature description:Listens for system theme change events.
    Parameter and description: function listener, the listener function for system theme change events.
    Response parameters:Object res
    Property
    Valid values and descriptions
    Type
    Description
    theme
    Dark: Dark theme
    Light: Light theme
    String
    The current theme of the system, with the value is light or dark.

    offThemeChange

    This API is called using wx.offThemeChange(function listener).
    Feature description:Removes the listener function for system theme change events.
    Parameter and description: function listener, the listener function passed from onThemeChange. If this parameter is not provided, all listener functions will be removed.
    Example:
    const listener = function (res) { console.log(res) }
    
    wx.onThemeChange(listener)
    wx.offThemeChange(listener) // Pass the same function object used for listening.

    onPageNotFound

    This API is called using wx.onPageNotFound(function listener).
    Notes:
    Developers can perform page redirection within the callback, but it must be handled synchronously. Asynchronous processing (such as asynchronous execution with setTimeout) is invalid.
    If the developer does not call wx.onPageNotFound to bind the listener, and does not state App.onPageNotFound, the host client will display a native "page not found" error page when attempting to navigate to a non-existent page.
    If the callback redirects to another page that does not exist, the host client will display the native "page not found" error page and will not trigger the callback a second time.
    Feature description:Listens for events where the mini program attempts to open a non-existent page. This event is triggered at the same time as the App.onPageNotFound.
    Parameter and description:Object res parameter, function listener, the listener function for the event where the mini program attempts to open a non-existent page.
    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 startup (for example, when entering from a shared link, the first page is the share page configured by the developer)

    offPageNotFound

    This API is called using wx.offPageNotFound(function listener).
    Feature description:Removes the listener function for the event where the mini program attempts to open a non-existent page.
    Parameter and description: function listener, the listener function passed from onPageNotFound. If this parameter is not provided, all listener functions will be removed.
    Example
    const listener = function (res) { console.log(res) }
    
    wx.onPageNotFound(listener)
    wx.offPageNotFound(listener) // Pass the same function object used for listening.

    onAppShow

    This API is called using wx.onAppShow(function listener).
    Note:
    In some versions, referrerInfo may return undefined if not present. It is recommended to check using options.referrerInfo &amp;&amp; options.referrerInfo.appId.
    Feature description:Listens for the event when the mini program switches to the frontend. This event's callback parameters are consistent with  App.onShow.
    Parameter and description:Object res parameter, function listener, the listener function for the event when the mini program switches to the frontend.
    Property
    Type
    Description
    path
    string
    The path of the mini program startup (code package path)
    scene
    number
    The scene value of the mini program startup
    query
    Object
    The query parameter of the mini program startup
    shareTicket
    string
    shareTicket
    referrerInfo
    Object
    The referrer of the information. Returned when the mini program is accessed from another mini program or an app. Otherwise, {} is returned. For details, see the notes above the table.
    forwardMaterials
    Array.<Object>
    An array of opened file information
    Structure of referrerInfo
    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
    Structure of forwardMaterials
    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
    Scenes with valid referrerInfo returned
    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

    offAppShow

    This API is called using wx.offAppShow(function listener).
    Feature description:Removes the listener function for the event when the mini program switches to the backend.
    Parameter and description: function listener, the listener function passed from onAppShow. If this parameter is not provided, all listener functions will be removed.
    Example
    const listener = function (res) { console.log(res) }
    
    wx.onAppShow(listener)
    wx.offAppShow(listener) // Pass the same function object used for listening.

    onAppHide

    This API is called using wx.onAppHide(function listener).
    Feature description:Listens for the event when the mini program switches to the backend. This event is triggered at the same time as the  App.onHide.
    Parameter and description: function listener, the listener function for events of mini program switching to the backend.

    offAppHide

    The API is called using wx.offAppHide(function listener).
    Feature description:Removes the listener function for the event when the mini program switches to the backend.
    Parameter and description: function listener, the listener function passed from onAppHide. If this parameter is not provided, all listener functions will be removed.
    const listener = function (res) { console.log(res) }
    
    wx.onAppHide(listener)
    wx.offAppHide(listener) // Pass the same function object used for listening.

    onUnhandledRejection

    This API is called using wx.onUnhandledRejection(function listener).
    Note:
    All unhandledRejection events can be captured by this listener, but only those of the error type will trigger an alarm in the mini program backend.
    Feature description:Listens for unhandled Promise rejection events.
    Parameter and description:Object res parameter, function listener, the listener function for unhandled Promise rejection events.
    Property
    Type
    Description
    reason
    string
    Rejection reason, typically an Error object
    promise
    Promise.<any>
    The rejected Promise object

    offUnhandledRejection

    This API is called using wx.offUnhandledRejection(function listener).
    Feature description:Removes the listener function for unhandled Promise rejection events.
    Parameter and description: function listener, the listener function passed from onUnhandledRejection. If this parameter is not provided, all listener functions will be removed.
    Example
    const listener = function (res) { console.log(res) }
    
    wx.onUnhandledRejection(listener)
    wx.offUnhandledRejection(listener) // Pass the same function object used for listening.

    Debug

    setEnableDebug

    This API is called using wx.setEnableDebug(Object object).
    Feature description:Sets whether to enable the debugging. It is effective even in the released version.
    Parameter and description:Object object.
    Property
    Type
    Default value
    ‍Required
    Description
    enableDebug
    boolean
    -
    Yes
    Whether to enable debugging
    success
    function
    -
    No
    Callback function for successful API calls
    fail
    function
    -
    No
    Callback function for failed API calls
    complete
    function
    -
    No
    Callback function executed when the API call is complete (regardless of success or failure)
    Example:
    // Enable debugging
    wx.setEnableDebug({
    enableDebug: true
    })
    
    // Disable debugging
    wx.setEnableDebug({
    enableDebug: false
    })
    Notes:
    You can also enable debugging in the development version or preview version first, and then switch to the released version where you can see the vConsole.

    getRealtimeLogManager

    This API is called using RealtimeLogManager wx.getRealtimeLogManager().
    Feature description: Gets the real-time log manager object.
    Return value: RealtimeLogManager.
    Example
    // For the mini program
    const 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')

    getLogManager

    Th is API is called using LogManager wx.getLogManager(Object object).
    Feature description:Gets the log manager object.
    Parameter and description:Object object.
    Property
    Type
    Default value
    ‍Required
    Description
    level
    number
    0
    No
    The valid values are 0 and1, where 0 indicates the that the 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.
    Return value:LogManager.
    Example:
    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])

    Console

    The console is a global object that can be accessed directly, with a set of features as follows. You can print logs in the IDE debugging panel and use vConsole to output logs on the client.

    LogManager

    The log manager instance, which can be accessed using  getLogManager , with the set of features as follows.

    RealtimeLogManager

    RealtimeTagLogManager

    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support