没有设备准备和没有console.log Xcode使用cordova1.5
这是我所有的代码,我既没有得到xcode的日志,也没有得到deviceReady事件(我也没有得到任何其他平台上。在Ubuntu + Android + Eclipse上我得到的控制台日志,但没有deviceReady 。也不在铬)
js / cordova-1.5.0.js存在并被加载,表示一个警告声明我已经放在那里。 任何线索我应该在哪里看? 提前致谢 ;)
<div id="d"></div> <script> function foo() {console.log('test'); document.getElementById('d').innerHTML += 'called';} window.setTimeout(foo, 5000); window.setTimeout(foo, 15000); window.setTimeout(foo, 25000); window.setTimeout(foo, 35000); alert('hi'); console.log('non timed console.log'); </script> <script src="js/cordova-1.5.0.js"></script> <script> document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { alert('deviceReady'); //somewhy this never happens } </script>
-
Console.log仅在deviceReady事件之后起作用
-
Phonegap为android和ios使用不同的phonegap.js文件,并且只有android版本与可下载的存档一起分发。 阅读Dhaval的评论,了解从哪里获得ios版本。
-
我使用Weinre进行debugging,几乎错过了它覆盖console.log方法,因此console.log不适用于weinre
正如Alex所指出的,console.log在您的PhoneGap设备准备好之后才可用。 通过调用它太快,你触发了一个参考错误。
删除所有现有的JavaScript,然后尝试使用它(用自定义代码replace倒数第二行的警报):
var app = { // denotes whether we are within a mobile device (otherwise we're in a browser) iAmPhoneGap: false, // how long should we wait for PhoneGap to say the device is ready. howPatientAreWe: 10000, // id of the 'too_impatient' timeout timeoutID: null, // id of the 'impatience_remaining' interval reporting. impatienceProgressIntervalID: null, // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // `load`, `deviceready`, `offline`, and `online`. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); // after 10 seconds, if we still think we're NOT phonegap, give up. app.timeoutID = window.setTimeout(function(appReference) { if (!app.iAmPhoneGap) // jeepers, this has taken too long. // manually trigger (fudge) the receivedEvent() method. appReference.receivedEvent('too_impatient'); }, howPatientAreWe, this); // keep us updated on the console about how much longer to wait. app.impatienceProgressIntervalID = window.setInterval(function areWeThereYet() { if (typeof areWeThereYet.howLongLeft == "undefined") { areWeThereYet.howLongLeft = app.howPatientAreWe; // create a static variable } areWeThereYet.howLongLeft -= 1000; // not so much longer to wait. console.log("areWeThereYet: Will give PhoneGap another " + areWeThereYet.howLongLeft + "ms"); }, 1000); }, // deviceready Event Handler // // The scope of `this` is the event. In order to call the `receivedEvent` // function, we must explicity call `app.receivedEvent(...);` onDeviceReady: function() { app.iAmPhoneGap = true; // We have a device. app.receivedEvent('deviceready'); // clear the 'too_impatient' timeout . window.clearTimeout(app.timeoutID); }, // Update DOM on a Received Event receivedEvent: function(id) { // clear the "areWeThereYet" reporting. window.clearInterval(app.impatienceProgressIntervalID); console.log('Received Event: ' + id); myCustomJS(app.iAmPhoneGap); // run my application. } }; app.initialize(); function myCustomJS(trueIfIAmPhoneGap) { // put your custom javascript here. alert("I am "+ (trueIfIAmPhoneGap?"PhoneGap":"a Browser")); }
我知道这个问题是在9个月之前问的,但我偶然发现了同样的问题。
如果你想debugging消息出现在weinre
控制台,你必须调用:
window.cordova.logger.useConsole(false);
装置准备好后。
更新:
看来,你需要运气得到控制台信息weinre
– 那坏:(
- 如何使用phonegap从Java脚本调用ios方法?
- 在使用IONIC和angularJS制作的ios设备上testingIOS应用程序
- Cordova应用程序无法在iOS 9上selectinput字段
- 苹果应用程序拒绝,因为Auth0 signUpLink在Cordova InAppBrowser中未打开,而是在系统浏览器(Safari)中打开,
- ios phonegap)我应该在哪里定位自定义推送通知声音?
- Apache Cordova / Visual Studio 2015工具无法在IOS模拟器中启动应用程序
- VS2013 Cordova iOS Remotebuild错误无法POST /build/tasks?command=build&vcordova=4.3.1&cfg=debug
- 阻止iframe中的链接导航/接pipecordova webview,特别是在ios中
- 如何防止键盘在iOS应用程序使用phonegap推高webview