2014-09-06 56 views
0

我建立一個應用程序與PhoneGap的建立,我試圖讓deviceready事件觸發,基於Adobe的文檔deviceready事件:http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#deviceready的PhoneGap構建不點火

我研究這個問題,並發現很多人都成功地克服了它。我嘗試了以下幾件事:

我添加以下行到我的index.html:(我也嘗試添加cordova.js)

<script type="text/javascript" src="phonegap.js"></script> 
<script type="text/javascript"> 
document.addEventListener("deviceready", function() { alert("Device Ready is Working"); }, false); 
</script> 

我已經添加了以下內容我的config.xml文件:

<gap:plugin name="org.apache.cordova.device" /> 

應用程序加載並運行得很好,但沒有設備準備好警報。我在華碩Transformer和Kindle Fire上嘗試過,但沒有成功。

的Index.html:

<!doctype html> 
<html lang="en" ng-app="Stories"> 
<head> 
    <meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" /> 
    <meta name="google-signin-clientid" content="615522017730.apps.googleusercontent.com" /> 
    <meta name="google-signin-scope" content="https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.login" /> 
    <meta name="google-signin-cookiepolicy" content="single_host_origin" /> 

    <link rel="Stylesheet" href="Styles/Lib/font-awesome.min.css" /> 
    <link rel="Stylesheet" href="Styles/Lib/bootstrap.min.css" /> 
    <link rel="Stylesheet" href="Styles/Core.css" /> 
    <link rel="Stylesheet" href="Styles/Mobile.css" /> 
</head> 
<body> 
    <div ng-view></div> 

    <script type="text/javascript" src="Scripts/Lib/angular.min.js"></script> 
    <script type="text/javascript" src="Scripts/Lib/angular-route.min.js"></script> 

    <script type="text/javascript" src="Scripts/Lib/jquery-2.1.1.min.js"></script> 
    <script type="text/javascript" src="Scripts/Lib/jquery.cookie.js"></script> 
    <script type="text/javascript" src="Scripts/Lib/bootstrap.min.js"></script> 
    <script type="text/javascript" src="Scripts/Lib/moment.min.js"></script> 
    <script type="text/javascript" src="Scripts/Lib/lodash.js"></script> 
    <script type="text/javascript" src="Scripts/Lib/ui-bootstrap-0.10.0.js"></script> 
    <script type="text/javascript" src="Scripts/Lib/ui-bootstrap-tpls-0.10.0.js"></script> 

    <script type="text/javascript" src="Scripts/App/Core.js"></script> 
    <script type="text/javascript" src="Scripts/App/Stories.js"></script> 

    <script type="text/javascript" src="Scripts/App.js"></script> 
    <script type="text/javascript" src="Scripts/Controllers.js"></script> 
    <script type="text/javascript" src="Scripts/Directives.js"></script> 
    <script type="text/javascript" src="Scripts/Services.js"></script> 
    <script type="text/javascript" src="Scripts/BSDirectives.js"></script> 

    <!--<script type="text/javascript" src="phonegap.js"></script>--> 
    <script type="text/javascript" src="cordova.js"></script> 
    <script type="text/javascript" src="Plugins/PushNotification.js"></script> 

    <div id="fb-root"></div> 

    <script type="text/javascript"> 
     document.addEventListener("deviceready", function() { alert("Device Ready is Working"); }, false); 
    </script> 

    <script type="text/javascript"> 
     window.fbAsyncInit = function() { 
      // TODO: Fix Channel location 
      FB.init({ 
       channelUrl: 'http://localhost:49499/stories/FBChannel.html', 
       appId: '474111489382243', 
       status: true, 
       cookie: true, 
       xfbml: true 
      }); 
     }; 
     (function (d) { 
      var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
      if (d.getElementById(id)) { return; } 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      ref.parentNode.insertBefore(js, ref); 
     }(document)); 
    </script> 

    <script type="text/javascript"> 
     (function() { 
      var po = document.createElement('script'); 
      po.type = 'text/javascript'; po.async = true; 
      po.src = 'https://apis.google.com/js/client:plusone.js?onload=render'; 
      var s = document.getElementsByTagName('script')[0]; 
      s.parentNode.insertBefore(po, s); 
     })(); 
    </script> 
</body> 
</html> 

config.xml文件:

<?xml version="1.0" encoding="utf-8" ?> 
<widget 
xmlns="http://www.w3.org/ns/widgets" 
xmlns:gap="http://phonegap.com/ns/1.0" 
xmlns:android="http://schemas.android.com/apk/res/android" 
id="com.asd.sdf" 
versionCode="1.0" 
version="1.0"> 
<name>asd</name> 
<description>asd</description> 
<author href="asd" email="asd">asd</author> 
<access origin="*" /> 
<gap:plugin name="org.apache.cordova.device" /> 
</widget> 
+0

這可能只是該警示是沒有上來,警告通過PhoneGap的完成。你需要能夠調試。嘗試Weinre http://people.apache.org/~pmuellr/weinre-docs/latest或在IOS上,您可以將enulator掛接到Safari http://phonegap-tips.com/articles/debugging-ios-phonegap-apps -with-之旅 - 網頁inspector.html。你需要看看JS控制檯說的是什麼,否則它很難處理事情。 – poperob 2014-09-06 03:11:35

+0

你在網頁瀏覽器中登入? – 2014-09-06 03:45:56

+0

創建一個新項目。默認的模板會加載一個閃爍的圖形,直到deviceready事件被觸發,然後告訴你最好去。正如poperob所說,警報不是測試事件處理程序的方式。 – kindasimple 2014-09-06 04:32:10

回答

-1

我想這個答案看起來不錯 - >Phonegap doesn't show alert

「因爲你試圖之前顯示一個警告phonegap/cordova framework is loaded。 $(document).ready(function(){is not to help you here,you must use this event to chec k如果PhoneGap的成功加載」

document.addEventListener("deviceReady", deviceReady, false); 

function deviceReady() { 
    // Now safe to use the PhoneGap API 
} 
+0

這與OP的代碼有什麼不同?您只創建了一個單獨的回調函數,但我相信它的工作原理完全相同。 – benka 2014-09-08 09:20:58

+0

是的,我根本沒有使用jQuery就緒事件,事實上它和我的代碼一樣,但是有一個回調。我的問題是爲什麼科爾多瓦準備好後警報不起作用。我不得不使用UI元素更改或Weinre來中繼設備就緒狀態。 – jmarkyston 2014-09-15 20:28:24