npm i --save nativescript-headset-detection
- 版本:1.0.0
- GitHub:
- NPM: https://npmjs.net.cn/package/nativescript-headset-detection
- 下载
- 昨日: 1
- 上周: 5
- 上月: 28
NativeScript 耳机检测插件
安装
tns plugin add nativescript-headset-detection
API
isConnected
要检查任何给定时刻的耳机,请使用此方法
JavaScript
var headsetDetection = require("nativescript-headset-detection");
headsetDetection.isConnected()
.then(function (connected) { console.log("Connected? " + connected); })
.catch(function (err) { console.log("Error: " + err)});
TypeScript
import * as headsetDetection from 'nativescript-headset-detection';
headsetDetection.isConnected()
.then(connected => console.log(`Connected? ${connected}`))
.catch(err => console.log(`Error: ${err}`));
onConnectionStateChanged
要监听耳机状态的更改,请使用此方法(将其添加到高级组件如 `app.[ts|js] 中很有意义);您可以将回调函数传递进去,每次耳机(连接/断开)时都会调用该函数
JavaScript
var headsetDetection = require("nativescript-headset-detection");
headsetDetection.onConnectionStateChanged(function (connected) {
console.log("Connection changed to: " + connected);
});
TypeScript
import * as headsetDetection from 'nativescript-headset-detection';
headsetDetection.onConnectionStateChanged(connected => console.log(`Connection changed to: ${connected}`));