【发布时间】:2019-09-10 13:07:56
【问题描述】:
我正在尝试使用 cordova-app-preferences 插件。
$( document ).ready(function() {
alert("doc ready");
function ok (value) {
alert("prefs.fetch value: "+value);
}
function fail (error) {
alert("prefs.fetch error: "+error);
}
var prefs;
try {
prefs = plugins.appPreferences;
}
catch (e) {
alert("can't find plugins.appPreferences");
}
prefs.fetch( ok, fail, "mode");
});
这失败了(捕获)。当我逐步使用 Safari 调试器时,插件未定义。我在我的 iPhone XS cordova run ios --device 上运行它,cordova 版本是 8.0.0。
我的 html 的编辑版本:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
<title>Login</title>
</head>
<body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/login.js"></script>
</body>
</html>
所以问题是:我缺少什么来获得对 plugins.appPreferences 的引用?
更新: 这个问题似乎是这个插件特有的。要复制,
cordova create plugin-test com.mydomain.ptest PLUG
cd plugin-test
cordova plugin add cordova-plugin-app-preferences --save
cordova platform add ios
cordova run ios --device
(失败,需要在xcode中指定代码签名者。)
cordova run ios --device
这一次它构建并运行。如果我打开 Safari 调试窗口,cordova.plugins 为空。
现在,如果我添加另一个插件(例如phonegap-plugin-barcodescanner)并再次运行它,cordova.plugins 存在,但只包含barcodescanner。
【问题讨论】: