cordova - 在 Typescript 上获取插件函数

标签 cordova typescript cordova-3 cordova-plugins

我正在尝试在 typescript 文件上使用一些cordova插件功能,但我无法构建该文件。想象一下,我想要访问设备平台和型号。有人可以帮我弄这个吗?我应该为插件的 js 文件上的每个函数创建接口(interface)吗?

提前致谢!

最佳答案

已经有相关定义:https://github.com/borisyankov/DefinitelyTyped/blob/master/cordova/plugins/Device.d.ts

interface Device {
    /** Get the version of Cordova running on the device. */
    cordova: string;
    /**
     * The device.model returns the name of the device's model or product. The value is set
     * by the device manufacturer and may be different across versions of the same product.
     */
    model: string;
    /** device.name is deprecated as of version 2.3.0. Use device.model instead. */
    name: string;
    /** Get the device's operating system name. */
    platform: string;
    /** Get the device's Universally Unique Identifier (UUID). */
    uuid: string;
    /** Get the operating system version. */
    version: string;
}

declare var device: Device;

您只需引用此文件(使用 ///<reference 注释),然后您可以执行以下操作:

console.log(device.model,device.platform);

关于cordova - 在 Typescript 上获取插件函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23339740/

相关文章:

ios - Ionic 2 InAppBrowser 选项不起作用

angular - Angular Material 中具有错误验证的ControlValueAccessor

cordova - PhoneGap 使用 HelloWorld 应用程序构建 ios 异常

javascript - Jquery Mobile 1.4 外部面板在导航到其他页面后不打开

git - PhoneGap/Cordova 3.0 项目的 .gitignore - 我应该提交什么?

android - phonegap logcat 错误外部/chromium/net/disk_cache/stat_hub.cc :213:

javascript - Cordova 和 HTML5 在播放声音时的差异

javascript - 在应用程序或组件加载 Angular 7 之前运行服务

javascript - 未捕获的类型错误 : Cannot read property 'querySelector' of null

arrays - Angular 2 循环遍历列表有一些延迟