Overview
API
The framework provides the developers with more JSAPI and OpenAPI capabilities so that they can launch diversified convenient services to the users.
Notes:
The APIs started with my.on are used to listen to the system events and accept one callback function as  the parameter. When the event is triggered, it calls the callback function, which will transfer to the related API started with my.off to cancel the listening relation. If the API started with my.off is called directly, all listening relations will be canceled. Example
Page({
onLoad() {
this.callback = this.callback.bind(this);
my.onBLECharacteristicValueChange(this.callback);
},
onUnload() {
// remove listener when page unload
my.offBLECharacteristicValueChange(this.callback);
},
callback(res) {
console.log(res);
},
});
All other API interfaces accept one object as the parameter. It is possible to specify success (call success), fail (call failure) and complete (call success or failure) cto receive the interface call result. The callback result is generally an object unless otherwise specified. If an error/errorMessage is included, it indicates call failure. The result value after the call is a promise object. Example
my.httpRequest({
url: '/x.htm',
success(res1) {},
}).then((res2) => {
// res1 === res2
},(res) => {
console.log(res.error, res.errorMessage);
})