Cordova - 使用Cordova開發iOS應用實戰3(添加Cordova控制檯插件)

Cordova - 使用Cordova開發iOS應用實戰3(添加Cordova控制檯插件)

前文介紹了經過 Safari 的 Web檢查器,能夠看到控制檯輸出的信息。但有時這樣調試代碼不太方便,若是在Xcode中的命令控制檯也能同步打印出調試信息就行了。
這個藉助Cordova的  cordova-plugin-console 插件便可實現。

1,給項目添加cordova-plugin-console插件
(1)在「終端」中進入項目文件夾
(2)輸入以下命令:
1
cordova plugin add cordova-plugin-console

2,測試樣例
咱們將首頁 index.html 修改爲以下內容,測試各類類型的控制檯信息。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
     <head>
         <title>Pause Example</title>
         <meta http-equiv= "Content-type" content= "text/html; charset=utf-8" >
             <script type= "text/javascript" charset= "utf-8" src= "cordova.js" ></script>
             <script type= "text/javascript" charset= "utf-8" >
                 document.addEventListener( "deviceready" , onDeviceReady, false );
                 function consoleLog(){
                     console.log( "console.log works well" );
                 }
                 function consoleError(){
                     console.error( "console.error works well" );
                 }
                 function consoleException(){
                     console.exception( "console.exception works well" );
                 }
                 function consoleWarn(){
                     console.warn( "console.warn works well" );
                 }
                 function consoleInfo(){
                     console.info( "console.info works well" );
                 }
                 function consoleDebug(){
                     console.debug( "console.debug works well" );
                 }
                 function consoleAssert(){
                     console.assert( "console.assert works well" );
                 }
                 function consoleDir(){
                     console.dir( "console.dir works well" );
                 }
                 function consoleDirxml(){
                     console.dirxml( "console.dirxml works well" );
                 }
                 function consoleTime(){
                     console.time( "console.time works well" );
                 }
                 function consoleTimeEnd(){
                     console.timeEnd( "console.timeEnd works well" );
                 }
                 function consoleTable(){
                     console.table( "console.table works well" );
                 }
             </script>
             <style type= "text/css" >
                 button {
                     width: 200px;height:26px;font-size: 20px;padding: 1px;margin-left: 50px;
                 }
             </style>
             </head>
         <body>
             <br/><button onclick= "consoleLog()" >consoleLog</button><br/>
             <br/><button onclick= "consoleError()" >consoleError</button><br/>
             <br/><button onclick= "consoleException()" >consoleException</button><br/>
             <br/><button onclick= "consoleWarn()" >consoleWarn</button><br/>
             <br/><button onclick= "consoleInfo()" >consoleInfo</button><br/>
             <br/> <button onclick= "consoleDebug()" >consoleDebug</button><br/>
             <br/><button onclick= "consoleAssert()" >consoleAssert</button><br/>
             <br/> <button onclick= "consoleDir()" >consoleDir</button><br/>
             <br/> <button onclick= "consoleDirxml()" >consoleDirxml</button><br/>
             <br/><button onclick= "consoleTime()" >consoleTime</button><br/>
             <br/><button onclick= "consoleTimeEnd()" >consoleTimeEnd</button><br/>
             <br/><button onclick= "consoleTable()" >consoleTable</button><br/>
     </body>
</html>
運行後頁面以下:
原文:Cordova - 使用Cordova開發iOS應用實戰3(添加Cordova控制檯插件)

3,測試結果
(1)把頁面上的按鈕都點一遍,看到Safari的Web檢查器中打印出了各類控制檯信息。
原文:Cordova - 使用Cordova開發iOS應用實戰3(添加Cordova控制檯插件)


(2)一樣在Xcode這邊的控制檯,一樣有調試信息打印出來
原文:Cordova - 使用Cordova開發iOS應用實戰3(添加Cordova控制檯插件)

原文出自: www.hangge.com  轉載請保留原文連接: http://www.hangge.com/blog/cache/detail_1139.html
相關文章
相關標籤/搜索