The js API of Mini App
consists of two parts: the standard ECMAScript js API and the neu extension API.
The js of standard ECMAScript is only the most basic js. The browser extends window, document, navigator and other objects based on it.
Mini App extends the neu object based on ECMAScript.
The js code of Mini App
, the web side runs in the browser. For the non-web side , the Android platform runs in the v8 engine, the iOS platform runs in the jscore engine that comes with iOS, and neither runs in the browser or webview.
On the non-web side, although it does not support the js API of browsers such as window, document, and navigator, it also supports standard ECMAScript.
Be careful not to equate in-browser js with standard js.
Therefore, the web side of Mini App also supports standard js, supports syntax such as if and for, and supports variable types such as strings, numbers, time, Boolean values, arrays, custom objects, and various processing methods. It's just that browser-specific objects such as window, document, and navigator are not supported.
errMsg
field, synchronous APIs will not. For example: getSystemInfoSync
will not have errMsg
in the returned result.Promisify
Specific strategy of API Promisify
:
For the asynchronous method, if no callback parameter such as success, fail or complete is passed in, the data will be returned as Promise. E.g.: neu.getImageInfo()
For asynchronous method with return object, at least one callback parameter of success, fail or complete should be passed in to obtain the return object. E.g.:
// Normal use
const task = neu.connectSocket(
success(res){
console.log(res)
}
)
// Promise
neu.connectSocket().then(res => {
// Here is the res of the success callback in normal use
// neu.connectSocket() will return the task object when used normally. If you want to get the task, don't use Promise
console.log(res)
})
API that does not proceed Promisify
:
neu.getSystemInfoSync()
neu.createMapContext()
neu.getBackgroundAudioManager()
promise
then method
callback if the call is successful. If the call fails, it will enter the catch method
callbackUse example:
Vue 3
// default method
neu.request({
url: "https://www.example.com/request",
success: (res) => {
console.log(res.data);
},
fail: (err) => {
console.error(err);
},
});
// call using Promise then/catch
neu
.request({
url: "https://www.example.com/request",
})
.then((res) => {
// The res parameter here is the same as the res parameter in the success callback when the default method is used
console.log(res.data);
})
.catch((err) => {
// The err parameter here is the same as the err parameter in the fail callback when the default method is used
console.error(err);
});
// use Async/Await method to call
async function request() {
try {
var res = await neu.request({
url: "https://www.example.com/request",
});
// The res parameter here is the same as the res parameter in the success callback when the default method is used
console.log(res);
} catch (err) {
// The err parameter here is the same as the err parameter in the fail callback when the default method is used
console.error(err);
}
}
Vue3
function isPromise(obj) {
return (
!!obj &&
(typeof obj === "object" || typeof obj === "function") &&
typeof obj.then === "function"
);
}
neu.addInterceptor({
returnValue(res) {
if (!isPromise(res)) {
return res;
}
const returnValue = [undefined, undefined];
return res
.then((res) => {
returnValue[1] = res;
})
.catch((err) => {
returnValue[0] = err;
})
.then(() => returnValue);
},
});
API | Description |
---|---|
timer | Execute the registered callback function after the timer expires |
neu.base64ToArrayBuffer | Convert Base64 string to ArrayBuffer object |
neu.arrayBufferToBase64 | Convert ArrayBuffer object to Base64 string |
Interceptor | Intercept calls such as Api and execute callbacks |
API | Description |
---|---|
neu.request | Initiate a network request |
API | Description |
---|---|
neu.connectSocket | Create a WebSocket connection |
neu.onSocketOpen | Listen for WebSocket open |
neu.onSocketError | Listen for WebSocket errors |
neu.sendSocketMessage | Send WebSocket message |
neu.onSocketMessage | Accept WebSocket messages |
neu.closeSocket | Close WebSocket connection |
neu.onSocketClose | Listen for WebSocket close |
API | Description |
---|---|
SocketTask.send | Send data via WebSocket connection |
SocketTask.close | Close WebSocket connection |
SocketTask.onOpen | Listen for WebSocket connection open events |
SocketTask.onClose | Listen for WebSocket connection close events |
SocketTask.onError | Listen for WebSocket error events |
SocketTask.onMessage | Listen for the message event received by the WebSocket server |
API | Description |
---|---|
neu.chooseImage | Choose an image from the album, or take a photo |
neu.previewImage | Preview image |
neu.closePreviewImage | Close preview image |
neu.getImageInfo | Get image information |
neu.saveImageToPhotosAlbum | Save image to system album |
API | Description |
---|---|
neu.chooseFile | Choose file from local |
API | Description |
---|---|
neu.getRecorderManager | Recording management |
API | Description | |
---|---|---|
neu.getBackgroundAudioManager | Background audio playback management | --> |
API | Description |
---|---|
neu.createInnerAudioContext | Audio component management |
API | Description |
---|---|
neu.chooseVideo | Choose video from album, or shoot |
neu.chooseMedia | Capture or select a picture or video from your phone's camera roll. |
neu.saveVideoToPhotosAlbum | Save video to system album |
neu.createVideoContext | Video component management |
API | Description | |
---|---|---|
neu.saveFile | save file | --> |
neu.getSavedFileList | Get the list of saved files | --> |
neu.getSavedFileInfo | Get saved file information | --> |
neu.removeSavedFile | Delete saved file information | --> |
neu.getFileInfo | Get file information | |
neu.openDocument | Open file |
API | Description |
---|---|
neu.getStorage | Get local data cache |
neu.getStorageSync | Get local data cache |
neu.setStorage | Set local data cache |
neu.setStorageSync | Set local data cache |
neu.getStorageInfo | Get information about local cache |
neu.getStorageInfoSync | Get information about local cache |
neu.removeStorage | Remove local cache content |
neu.removeStorageSync | Delete local cache content |
neu.clearStorage | Clear local data cache |
neu.clearStorageSync | Clear local data cache |
API | Description |
---|---|
neu.getLocation | Get current location |
neu.chooseLocation | Open the map and choose the location |
API | Description |
---|---|
neu.openLocation | Open built-in map |
API | Description |
---|---|
neu.createMapContext | Map component control |
API | Description |
---|---|
neu.getSystemInfo | Get system information |
neu.getSystemInfoSync | Get system information |
neu.getDeviceInfo | Get basic device information |
neu.getWindowInfo | Get window information |
neu.getAppBaseInfo | Get base information |
neu.getAppBaseInfo | Get base information |
neu.getHostLanguage | Get the host App language |
neu.getHostFontSize | Get the host App font size |
| neu.canIUse | Determine whether the application's API, callback, parameters, components, etc. are available in the current version |
API | Description |
---|---|
neu.getNetworkType | Get network type |
neu.onNetworkStatusChange | Monitor network status changes |
neu.offNetworkStatusChange | Cancel monitoring network status changes |
API | Description |
---|---|
neu.onAccelerometerChange | Monitor acceleration data |
neu.offAccelerometerChange | Cancel monitoring acceleration data |
neu.startAccelerometer | Start monitoring acceleration data |
neu.stopAccelerometer | Stop monitoring acceleration data |
API | Description |
---|---|
neu.onCompassChange | Monitor compass data |
neu.offCompassChange | Cancel monitoring compass data |
neu.startCompass | Start listening for compass data |
neu.stopCompass | Stop monitoring compass data |
API | Description |
---|---|
neu.makePhoneCall | make a call |
API | Description | |
---|---|---|
neu.scanCode | Scan code | --> |
API | Description |
---|---|
neu.setClipboardData | Set clipboard content |
neu.getClipboardData | Get clipboard content |
API | Description |
---|---|
neu.setScreenBrightness | Set screen brightness |
neu.getScreenBrightness | Get screen brightness |
neu.setKeepScreenOn | Set whether to keep the always-on state |
API | Description |
---|---|
neu.vibrate | Vibrate phone |
neu.vibrateLong | Make the phone vibrate for a long time |
neu.vibrateShort | Make the phone vibrate for a short time |
API | Description |
---|---|
neu.addPhoneContact | Add phone contacts |
API | Description |
---|---|
neu.openBluetoothAdapter | Initialize the Bluetooth module |
neu.startBluetoothDevicesDiscovery | Discover nearby Bluetooth peripherals |
neu.onBluetoothDeviceFound | Listen for new device found events |
neu.stopBluetoothDevicesDiscovery | stop discovery |
neu.onBluetoothAdapterStateChange | Listen for bluetooth adapter state change events |
neu.getConnectedBluetoothDevices | Get connected devices by uuid |
neu.getBluetoothDevices | Get discovered bluetooth devices |
neu.getBluetoothAdapterState | Get the state of the native Bluetooth adapter |
neu.closeBluetoothAdapter | Close the bluetooth module |
API | Description |
---|---|
neu.writeBLECharacteristicValue | Write binary data to Bluetooth low energy device characteristic value |
neu.readBLECharacteristicValue | Read the binary data value of the characteristic value of the Bluetooth low energy device |
neu.onBLEConnectionStateChange | Listen for Bluetooth Low Energy connection state change events |
neu.onBLECharacteristicValueChange | Monitor the characteristic value change event of Bluetooth low energy devices |
neu.notifyBLECharacteristicValueChange | Enable the notify function when the characteristic value of a Bluetooth low energy device changes, subscribe to the characteristic |
neu.getBLEDeviceServices | Get all Bluetooth device services (service) |
neu.getBLEDeviceCharacteristics | Get all the characteristic values (characteristic) in a service of a Bluetooth device |
neu.createBLEConnection | Connect to a Bluetooth Low Energy device |
neu.closeBLEConnection | Disconnect from a Bluetooth Low Energy device |
API | Description |
---|---|
neu.onBeaconServiceChange | Listen for iBeacon service status change events |
neu.onBeaconUpdate | Listen for iBeacon device update events |
neu.getBeacons | Get all searched iBeacon devices |
neu.startBeaconDiscovery | Stop searching for nearby iBeacon devices |
neu.stopBeaconDiscovery | Start searching for iBeacon devices nearby |
API | Description | |
---|---|---|
neu.startSoterAuthentication | Start biometric authentication | |
neu.checkIsSupportSoterAuthentication | Get the supported biometric authentication methods | |
neu.checkIsSoterEnrolledInDevice | The interface to obtain whether biometric information such as fingerprints is entered in the device | --> |
API | Description |
---|---|
neu.showToast | Show prompt box |
neu.showLoading | Show loading prompt |
neu.hideToast | Hide the prompt box |
neu.hideLoading | Hide loading prompt box |
neu.showModal | Show modal popup |
neu.showActionSheet | Show menu list |
API | Description |
---|---|
neu.setNavigationBarTitle | Set the current page title |
neu.setNavigationBarColor | Set page navigation bar color |
neu.showNavigationBarLoading | Show navigation bar loading animation |
neu.hideNavigationBarLoading | Hide navigation bar loading animation |
API | Description |
---|---|
neu.setTabBarItem | Dynamically set the content of a tabBar item |
neu.setTabBarStyle | Dynamically set the overall style of the tabBar |
neu.hideTabBar | hide tabBar |
neu.showTabBar | Show tabBar |
neu.setTabBarBadge | Add text to the upper right corner of a tabBar item |
neu.removeTabBarBadge | Remove the text in the upper right corner of a tabBar item |
neu.showTabBarRedDot | Show the red dot in the upper right corner of a tabBar item |
neu.hideTabBarRedDot | Hide the red dot in the upper right corner of a tabBar item |
API | Description |
---|---|
neu.createAnimation | Create an animation instance animation. Call the instance's method to describe the animation. Finally, the animation data is exported through the export method of the animation instance and passed to the animation property of the component. |
API | Description |
---|---|
neu.pageScrollTo | Scroll the page to the target position. |
API | Description |
---|---|
neu.createCanvasContext | Create drawing context |
neu.canvasToTempFilePath | Save the canvas content to a file |
neu.canvasGetImageData | Get canvas image data |
neu.canvasPutImageData | Set canvas image data |
API | Description |
---|---|
onPullDownRefresh | Listen to the page user pull down refresh event |
neu.startPullDownRefresh | Start pull down refresh |
neu.stopPullDownRefresh | Stop pull-down refresh of the current page |
API | Description |
---|---|
neu.createSelectorQuery | Create query request |
selectorQuery.select | Select a single node based on selector |
selectorQuery.selectAll | Select all nodes according to selector |
selectorQuery.selectViewport | Select display area |
selectorQuery.exec | Execute query request |
nodesRef.boundingClientRect | Get layout position and size |
nodesRef.scrollOffset | Get scroll position |
nodesRef.fields | Get any field |
API | Description |
---|---|
neu.createIntersectionObserver | Create IntersectionObserver object |
intersectionObserver.relativeTo | Specify reference node |
intersectionObserver.relativeToViewport | Specify the page display area as the reference area |
intersectionObserver.observe | Specify the target node and start listening |
intersectionObserver.disconnect | stop listening |
API | Description |
---|---|
neu.navigateTo | Keep the current page, jump to a page in the app, use neu.navigateBack to return to the original page |
neu.redirectTo | Close the current page and jump to a page in the app |
neu.reLaunch | Close all pages, open to a page in the app |
neu.switchTab | Jump to the tabBar page and close all other non-tabBar pages |
neu.navigateBack | Close the current page and return to the previous page or multi-level page |
API | Description | |
---|---|---|
neu.hideKeyboard | Hide the displayed soft keyboard. If the soft keyboard is not displayed, do nothing. | |
neu.onKeyboardHeightChange | Monitor keyboard height changes | --> |
neu.offKeyboardHeightChange | Cancel listening for keyboard height change events | --> |
neu.getSelectedTextRange | After input, textarea, etc. focus, get the cursor position of the input box |
API | Description |
---|---|
neu.login | Register |
neu.getUserProfile | Get User Info |
neu.getAuthCode | Get Auth Code |
neu.share | share |
neu.shareMiniAppMessage | share MiniApp to Message |
neu.requestPayment | Pay |
API | Description |
---|---|
neu.setEnableDebug | Open the debug switch |
neu.launchApp | Open Other Apps |
neu.restartMiniProgram | Restart Mini App |
neu.exitMiniProgram | Exit Mini App |
Due to document synchronization reasons, the APIs listed on this page may not be complete. If you do not find the relevant API in this article, you can find it in the tree on the left or use the search function in the upper right corner of the document.