README
Wechat Miniapp Promisify
Read this in other languages: English, 简体中文
wx-miniapp-promisify
is a simple wrapper to return the most commonly used wx async functions as Promises. This library should only be used in a WeChat miniapp.
Table of Contents
- How to install via NPM in WeChat miniapp
- How to use wx-miniapp-promisify
- Helper Methods
- Supported Methods
How to install via NPM in WeChat miniapp
- Go to your wechat app folder and run
npm install wx-miniapp-promisify
. - In your WeChat IDE, ensure the following,
- In "Settings > Project Settings", ensure that "Transpile ES6 to ES5" and "Use NPM module" is checked.
- Run npm build in "Tools > Build npm".
How to use wx-miniapp-promisify
- Using
import
orrequire
statements to include the library into your code.
// Example with "import" syntax in page/index.js
import wxPromise from 'wx-miniapp-promisify';
// Example with "require" syntax in page/index.js
let wxPromise = require('wx-miniapp-promisify');
wx-miniapp-promisify
functions are a replica ofwx
async functions.
// Example code for a "normal wx.request"
let normalResponse = wx.request({
url: 'test.php', // imaginary url endpoint
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
success (res) {
console.log(res.data)
}
});
// Example using "wx-miniapp-promisify"
let promiseResponse = wxPromise.request({
url: 'test.php', // imaginary url endpoint
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
success (res) {
console.log(res.data)
}
});
Helper Methods
Method Name | Parameters | Type | Return Value | Example |
---|---|---|---|---|
isPromisable |
methodName |
string |
boolean |
wxPromise.isPromisable('newWxMethod') |
Supported Methods
- downloadFile
- request
- uploadFile
- closeSocket
- connectSocket
- sendSocketMessage
- getAvailableAudioSources
- pauseVoice
- playVoice
- setInnerAudioOption
- stopVoice
- getBackgroundAudioPlayerState
- pauseBackgroundAudio
- playBackgroundAudio
- seekBackgroundAudio
- stopBackgroundAudio
- loadFontFace
- chooseImage
- compressImage
- getImageInfo
- previewImage
- saveImageToPhotosAlbum
- startRecord
- stopRecord
- chooseVideo
- saveVideoToPhotosAlbum
- getFileInfo
- getSavedFileInfo
- getSavedFileList
- openDocument
- removeSavedFile
- saveFile
- getStorage
- getStorageInfo
- removeStorage
- setStorage
- chooseLocation
- getLocation
- openLocation
- startAccelerometer
- stopAccelerometer
- getBatteryInfo
- closeBluetoothAdapter
- getBluetoothAdapterState
- getBluetoothDevices
- getConnectedBluetoothDevices
- openBluetoothAdapter
- startBluetoothDevicesDiscovery
- stopBluetoothDevicesDiscovery
- closeBLEConnection
- createBLEConnection
- getBLEDeviceCharacteristics
- getBLEDeviceServices
- notifyBLECharacteristicValueChange
- readBLECharacteristicValue
- writeBLECharacteristicValue
- getClipboardData
- setClipboardData
- startCompass
- stopCompass
- addPhoneContact
- startGyroscope
- stopGyroscope
- getBeacons
- startBeaconDiscovery
- stopBeaconDiscovery
- startDeviceMotionListening
- stopDeviceMotionListening
- getNetworkType
- getHCEState
- sendHCEMessage
- startHCE
- stopHCE
- makePhoneCall
- scanCode
- getScreenBrightness
- setKeepScreenOn
- setScreenBrightness
- vibrateLong
- vibrateShort
- connectWifi
- getConnectedWifi
- getWifiList
- setWifiList
- startWifi
- stopWifi
- setBackgroundColor
- setBackgroundTextStyle
- hideLoading
- hideToast
- showActionSheet
- showLoading
- showModal
- showToast
- hideNavigationBarLoading
- setNavigationBarColor
- setNavigationBarTitle
- showNavigationBarLoading
- startPullDownRefresh
- stopPullDownRefresh
- pageScrollTo
- setTopBarText
- hideTabBar
- hideTabBarRedDot
- removeTabBarBadge
- setTabBarBadge
- setTabBarItem
- setTabBarStyle
- showTabBar
- showTabBarRedDot
- chooseAddress
- authorize
- addCard
- openCard
- chooseInvoice
- chooseInvoiceTitle
- checkSession
- login
- navigateBackMiniProgram
- navigateToMiniProgram
- requestPayment
- getSetting
- openSetting
- checkIsSoterEnrolledInDevice
- checkIsSupportSoterAuthentication
- startSoterAuthentication
- getUserInfo
- getWeRunData
- canvasGetImageData
- canvasPutImageData
- canvasToTempFilePath
- getExtConfig
- navigateBack
- navigateTo
- redirectTo
- reLaunch
- switchTab
- getShareInfo
- hideShareMenu
- showShareMenu
- updateShareMenu
- getSystemInfo