YHExplorer前端调用说明.md
3.65 KB
基本使用
<!-- 组装参数,下面是基本参数结构 -->
var params = { "ability":"action", "options":{"optionKey":"optionValue"} };
<!-- 触发机能 -->
yohoInterface.triggerEvent(onSuccess, onFail, params);
onSuccess
回调里面会传递结果。
###具体定义
1. 摄像头
-
拍照/访问相册
<!-- quality(照片质量) 0-100 pictureSourceType(照片源): 1. 访问相册 SAVEDPHOTOALBUM 2. 摄像头 CAMERA targetSize(照片尺寸,单位:像素): 如果其中某个设为0,则认为等比缩放 --> var params = { "Native_Camera":"takePicture", "options":{ "quality":75, "pictureSourceType":"CAMERA", "targetSize":{ "width":100, "height":100 } } };
-
展示获取的照片Example
function onSuccess(imageData) { var image = document.getElementById('myImage'); image.src = "data:image/jpeg;base64," + imageData; }
2. LBS
- 获取Location ```javascript var params = { "Native_LBS":"getLocation" };
function onSuccess(coordinate) { alert('Coordinate Latitude: ' + coordinate.latitude + '\n' + 'Coordinate Longitude: ' + coordinate.longitude); };
* 获取所在地理位置信息
```javascript
var params = { "Native_LBS":"getLocationDetail" };
<!-- 回调Example:
国家 - placemark.country
国家代号 - placemark.countryCode
城市 - placemark.city
省 - placemark.state
街道 - placemark.street
区 - placemark.sublocality
完整地址名称 - placemark.name
-->
function onSuccess(placemark) {
alert('name: ' + placemark.name + '\n' +
'countryCode: ' + placemark.countryCode + '\n' +
'country: ' + placemark.country + '\n' +
'state: ' + placemark.state + '\n' +
'city: ' + placemark.city + '\n' +
'sublocality: ' + placemark.sublocality + '\n' +
'street: ' + placemark.street);
};
3. Device
- 获取设备信息 ```javascript var params = { "Native_Device":"getDeviceInfo" };
function onSuccess(device) { alert('Model: ' + device.model + '\n' + 'Platform: ' + device.platform + '\n' + 'OSVersion: ' + device.version); };
##### 4. Media
* 调用iOS媒体播放器
```javascript
var params = { "Native_Media":"playMedia", "options":{ "url":"http://xxxxxxx.mp4" } };
5. 传感器
-
震动
<!-- duration为震动时长 --> var params = { "Native_Motion":"vibrate", "options":{ "duration":1.2 } };
-
获取加速计状态
<!-- period为观察间隔,单位是毫秒 --> var params = { "Native_Motion":"watchAcceleration", "options":{ "period":1000 } };
function onSuccess(acceleration) { alert('Acceleration X: ' + acceleration.x + '\n' + 'Acceleration Y: ' + acceleration.y + '\n' + 'Acceleration Z: ' + acceleration.z + '\n' + 'Timestamp: ' + acceleration.timestamp + '\n'); };
* 停止获取加速计状态(不需要加速计状态时,务必调用来停止加速计刷新)
```javascript
var params = { "Native_Motion":"clearWatchAcceleration" };
6. FileSystem
- 获取目录 ```javascript <!-- Documents目录 --> var params = { "Native_FS":"getDocumentsPath" }; <!-- tmp目录 --> var params = { "Native_FS":"getTemporaryPath" }; <!-- cache目录 --> var params = { "Native_FS":"getCachePath" };
function onSuccess(path) { alert('path: ' + path); };
* 删除文件
```javascript
var params = { "Native_FS":"deleteItemAtPath", "options":{ "path":"itemPath" } };
- 拷贝文件
javascript var params = { "Native_FS":"copyItem", "options":{ "srcPath":"xxx", "dstPath":"xxx" } };