尝试使用TorchPluging时出现以下错误:
file:///android_asset/www/web/index.html: Line 12 : Uncaught TypeError: Cannot read property 'Torch' of undefined
我在config.xml中添加了插件(我认为在较新的phonegap版本中,它已从plugins.xml更改为config.xml?)
以下是我的整个index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Flashlight</title>
<script type="text/javascript" charset="utf-8" src="js/cordova-2.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/Torch.js"></script>
<script type="text/javascript" charset="utf-8" src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function turnTorchOn(){
window.plugins.Torch.turnOn(
function() { console.log( "turnOn" ) } // success
, function() { console.log( "error" ) }); // error
}
</script>
</head>
<body>
<button id="turnOnButton" name="turnOnButton" > Turn on Flashlight</button>
<script>
$('#turnOnButton').click(function(){
alert("will turn on now");
turnTorchOn();
alert("called turnOn done");
});
</script>
</body>
</html>
答案 0 :(得分:2)
将旧样式插件更新为可在2.0.0+中运行的插件实际上并不难。你需要:
我写了几篇关于这个话题的博客文章。如果您确实按照它们更新了Torch插件,则应提交拉取请求,以便每个人都能享受您的工作。
2.0.0插件 - http://simonmacdonald.blogspot.ca/2012/08/so-you-wanna-write-phonegap-200-android.html 弃用的API - http://simonmacdonald.blogspot.ca/2012/07/phonegap-android-plugins-sometimes-we.html