API overview

更新时间:
复制 MD 格式

This topic lists all APIs for mPaaS miniapps. For details, see the corresponding API reference.

Interface

Navigation bar

Name

Description

my.getTitleColor

Gets the background color of the navigation bar.

my.hideBackHome

Hides the "Back to Home" icon on the title bar.

my.hideNavigationBarLoading

Hides the loading animation in the navigation bar on the current page.

my.showNavigationBarLoading

Shows the loading animation in the navigation bar on the current page.

my.setNavigationBar

Sets the style of the navigation bar, including the title, background color, bottom border color, and the logo image in the upper-left corner.

Tab bar

Name

Description

my.hideTabBar

Hides the tab bar.

my.hideTabBarRedDot

Hides the red dot in the upper-right corner of a tab.

my.removeTabBarBadge

Removes the text from the upper-right corner of a tab.

my.setTabBarBadge

Adds text to the upper-right corner of a tab. This can be used to display a notification dot with the number of unread messages.

my.setTabBarItem

Dynamically sets the content of a tab item.

my.setTabBarStyle

Dynamically sets the overall style of the tab bar, such as text color, background color, and border color.

my.showTabBar

Displays tabs.

my.showTabBarRedDot

Shows the red dot in the upper-right corner of a tab.

onTabItemTap

Triggers when a tab is tapped. This can be used to listen for tab tap events.

tabBar FAQ

Answers to frequently asked questions about the tab bar.

Routing

Name

Description

my.switchTab

Switches to a specified tab bar page and closes all other non-tab bar pages.

my.reLaunch

Closes all current pages and navigates to a specified page in the application.

my.redirectTo

Closes the current page and navigates to a specified page in the application.

my.navigateTo

Navigates from the current page to a specified page in the application.

my.navigateBack

Closes the current page and returns to the previous page or a page multiple levels back.

Routing FAQ

Answers to frequently asked questions about routing.

Interaction feedback

Name

Description

my.alert

Alerts

my.confirm

Displays a confirmation dialog box.

my.prompt

Displays a dialog box that prompts the user to enter text.

my.showToast

Shows a toast message that can disappear after a specified number of seconds.

my.hideToast

Hides the hint text.

my.showLoading

Shows a loading indicator.

my.hideLoading

Hides the loading indicator.

my.showActionSheet

Shows an action sheet menu.

Pull-to-refresh

Name

Description

onPullDownRefresh

Listens for the pull-to-refresh event on the current page.

my.stopPullDownRefresh

Stops the pull-to-refresh action on the current page.

my.startPullDownRefresh

Starts the pull-to-refresh action.

Contacts

Name

Description

my.choosePhoneContact

Selects a contact's phone number from the local system's address book.

Select city

Name

Description

my.chooseCity

Opens the city selection list.

my.onLocatedComplete

Defines a custom onLocatedComplete function to listen for the callback after geolocation is complete. This applies only when the setLocatedCity property in my.chooseCity is set to true.

my.setLocatedCity

Modifies the name of the default located city in my.chooseCity.

Select date

Name

Description

my.datePicker

Opens the date picker.

Animation

Name

Description

my.createAnimation

Creates an animation instance.

Canvas

Name

Description

my.createCanvasContext

Creates a canvas drawing context.

Keyboard

Name

Description

my.hideKeyboard

Hides the keyboard.

Scroll

Name

Description

my.pageScrollTo

Scrolls the page to a target position.

Node query

Name

Description

my.createSelectorQuery

Gets a SelectorQuery object for node queries.

Option selector

Name

Description

my.optionsSelect

A component similar to the native Safari select component, but with more features. It is often used as a replacement for the select component or for selecting two-level data. Note: Filter interaction between the two levels of data is not supported.

Cascading selection

Name

Description

my.multiLevelSelect

Used for business scenarios that require multi-level cascading data selection, such as selecting a province, city, and district.

Set background window

Name

Description

my.setBackgroundColor

Dynamically sets the background color of the window.

my.setBackgroundTextStyle

Dynamically sets the font and loading graphic style for the pull-down background.

Set whether a page supports pull-down

Name

Description

my.setCanPullDown

Sets whether a page supports the pull-down gesture. By default, pages in a miniapp support this gesture.

Set optionMenu

Name

Description

my.setOptionMenu

Configures an extra icon in the optionMenu of the navigation bar. Tapping the icon triggers onOptionMenuClick.

Multimedia

Images

Name

Description

my.chooseImage

Takes a photo or selects an image from the phone's album.

my.previewImage

Previews an image.

my.saveImage

Saves an online image to the phone's album.

my.compressImage

Compresses an image.

my.getImageInfo

Gets image information.

Cache

Name

Description

my.setStorage

Stores data in the local cache with a specified key. This overwrites any existing data for that key.

my.setStorageSync

Synchronously stores data in the local cache with a specified key.

my.getStorage

Asynchronously gets cached data.

my.getStorageSync

Synchronously gets cached data.

my.removeStorage

Asynchronously removes cached data.

my.removeStorageSync

Synchronously removes cached data.

my.clearStorage

Asynchronously clears the local data cache.

my.clearStorageSync

Synchronously clears the local data cache.

my.getStorageInfo

Asynchronously gets information about the current storage.

my.getStorageInfoSync

Synchronously gets information about the current storage.

Files

Name

Description

my.saveFile

Saves a file to the local device. The total storage capacity for local files is 10 MB.

my.getFileInfo

Gets file information.

my.getSavedFileInfo

Gets information about a saved file.

my.getSavedFileList

Gets a list of all saved files.

my.removeSavedFile

Deletes a saved file.

Location

Name

Description

my.chooseLocation

Selects a geographical location using the built-in map.

my.getLocation

Gets the user's current geographical location.

my.openLocation

Views a location using the mPaaS miniapp's built-in map.

Network

Name

Description

my.request

Makes a network request from the miniapp.

my.uploadFile

Uploads a local resource to the developer's server.

my.downloadFile

Downloads a file resource to the local device.

my.connectSocket

Creates a WebSocket connection.

my.onSocketOpen

Listens for the WebSocket connection open event.

my.offSocketOpen

Stops listening for the WebSocket connection open event.

my.onSocketError

Listens for WebSocket errors.

my.offSocketError

Stops listening for WebSocket errors.

my.sendSocketMessage

Sends data through the WebSocket connection.

my.onSocketMessage

Listens for messages received from the server over the WebSocket connection.

my.offSocketMessage

Stops listening for messages received from the server over the WebSocket connection.

my.closeSocket

Closes the WebSocket connection.

my.onSocketClose

Listens for the WebSocket connection close event.

my.offSocketClose

Stops listening for the WebSocket connection close event.

Device

canIUse

Name

Description

my.canIUse

Checks if an API, input parameter, return value, component, or property is supported in the current version of the miniapp.

Get base library version number

Name

Description

my.SDKVersion

Gets the version number of the base libraries. This value is for reference only. Do not base your code logic on this value.

System info

Name

Description

my.getSystemInfo

Gets mobile phone system information.

my.getSystemInfoSync

Synchronously gets mobile phone system information.

Network status

Name

Description

my.getNetworkType

Gets the current network status.

my.onNetworkStatusChange

Starts listening for changes in the network status.

my.offNetworkStatusChange

Stops listening for changes in the network status.

Clipboard

Name

Description

my.getClipboard

Gets data from the clipboard.

my.setClipboard

Sets data on the clipboard.

Shake

Name

Description

my.watchShake

Invokes the shake feature. Each time this API is called, a callback is triggered after the phone is shaken. To listen again, call this API again.

Vibration

Name

Description

my.vibrate

Invokes the vibration feature.

my.vibrateLong

Vibrates for a long duration (400 ms).

my.vibrateShort

Vibrates for a short duration (40 ms).

Accelerometer

Name

Description

my.onAccelerometerChange

Listens for accelerometer data.

my.offAccelerometerChange

Stops listening for accelerometer data.

Gyroscope

Name

Description

my.onGyroscopeChange

Listens for gyroscope data change events.

my.offGyroscopeChange

Stops listening for gyroscope data.

Compass

Name

Description

my.onCompassChange

Listens for compass data.

my.offCompassChange

Stops listening for compass data.

Make a phone call

Name

Description

my.makePhoneCall

Makes a phone call.

User screenshot event

Name

Description

my.onUserCaptureScreen

Listens for user-initiated screenshot events.

my.offUserCaptureScreen

Stops listening for screenshot events.

Screen brightness

Name

Description

my.setKeepScreenOn

Sets whether to keep the screen on.

my.getScreenBrightness

Gets the screen brightness.

my.setScreenBrightness

Sets the screen brightness.

Add a phone contact

Name

Description

my.addPhoneContact

Lets a user save form data to the phone's address book by either creating a new contact or adding to an existing contact.

Scan code

Name

Description

my.scan

Invokes the code scanning feature.

Bluetooth

Name

Description

my.openBluetoothAdapter

Initializes the miniapp's Bluetooth module.

my.closeBluetoothAdapter

Closes the local device's Bluetooth module.

my.getBluetoothAdapterState

Gets the status of the local device's Bluetooth module.

my.startBluetoothDevicesDiscovery

Starts searching for nearby Bluetooth peripherals.

my.stopBluetoothDevicesDiscovery

Stops searching for nearby Bluetooth peripherals.

my.getBluetoothDevices

Gets all discovered Bluetooth devices, including those already connected to the local device.

my.getConnectedBluetoothDevices

Gets all connected devices.

my.connectBLEDevice

Connects to a Bluetooth Low Energy (BLE) device.

my.disconnectBLEDevice

Disconnects from a BLE device.

my.writeBLECharacteristicValue

Writes data to a BLE device's characteristic.

my.readBLECharacteristicValue

Reads data from a BLE device's characteristic.

my.notifyBLECharacteristicValueChange

Enables notifications for characteristic value changes on a BLE device.

my.getBLEDeviceServices

Gets all services of a Bluetooth device.

my.getBLEDeviceCharacteristics

Gets all characteristics of a Bluetooth device.

my.onBluetoothDeviceFound

Triggers when a new Bluetooth device is found.

my.offBluetoothDeviceFound

Stops listening for the new Bluetooth device found event.

my.onBLECharacteristicValueChange

Listens for characteristic value change events on a BLE device.

my.offBLECharacteristicValueChange

Stops listening for characteristic value change events on a BLE device.

my.onBLEConnectionStateChanged

Listens for BLE connection error events, such as device loss or abnormal disconnection.

my.offBLEConnectionStateChanged

Stops listening for BLE connection state change events.

my.onBluetoothAdapterStateChange

Listens for changes in the local device's Bluetooth adapter state.

my.offBluetoothAdapterStateChange

Stops listening for changes in the local device's Bluetooth adapter state.

Error codes

A reference table of Bluetooth API error codes.

Data security

Name

Description

my.rsa

Asymmetric encryption.

Share

Name

Description

onShareAppMessage

Defines the onShareAppMessage function in a page to set the sharing information for that page.

my.hideShareMenu

Hides the share button.

Miniapp current running version type

Name

Description

my.getRunScene

Gets the current running version of the miniapp.

Custom analytics

Name

Description

my.reportAnalytics

An interface for reporting custom analytics data.

Miniapp navigation

Name

Description

my.navigateToMiniProgram

Navigates to another miniapp.

my.navigateBackMiniProgram

Navigates back to the previous miniapp. This call is successful only if the current miniapp was launched from another miniapp.

Web-view component control

Name

Description

my.createWebViewContext

Creates and returns a webViewContext object for a web-view.

webViewContext

The webViewContext object is bound to a web-view component using a webviewId. You can use this object to implement various features.