gpt4 book ai didi

javascript - 未捕获的类型错误 : Object # has no method 'vibrate'
转载 作者:行者123 更新时间:2023-11-29 17:49:17 25 4
gpt4 key购买 nike

我在 cordova 3.4.0 for android 上创建了一个 hello world 项目。不知何故,我的对话框/通知插件无法正常工作。我是这样添加插件的

cordova plugin add org.apache.cordova.dialogs

并在我的 android list 中添加了这一行:

<uses-permission android:name="android.permission.VIBRATE" />

当我测试插件时,它的方法“警报”、“提示”、“确认”和“蜂鸣”非常有效,但是一旦我想调用振动方法,就像我在 Cordova API 中读到的那样它崩溃了。这是我的代码:

$(document).ready(function(){
document.addEventListener("deviceready", function() {
navigator.notification.vibrate(1000);
}, false);
})

我在 logcat 中遇到此错误消息:

Uncaught TypeError: Object #<Object> has no method 'vibrate'

我像这样注销了 navigator.notification 的所有方法:

var res = [];
for(var m in navigator.notification) {
if(typeof navigator.notification[m] == "function") {
res.push(m)
}
}
console.log(res);

结果:“alert,confirm,prompt,beep,activityStart,activityStop,progressStart,progressStop,progressValue”

有谁知道为什么 navigator.notification 中没有振动方法?

编辑

我的 res/config.xml 中有这个条目:

<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>

最佳答案

出于某种原因,振动不再包含在通知插件中,而是包含在一个额外的插件中:

https://github.com/apache/cordova-plugin-vibration/blob/master/doc/index.md

关于javascript - 未捕获的类型错误 : Object #<Object> has no method 'vibrate' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24241764/

25 4 0