2016-02-10 20 views
0

我正在製作能夠拍照並將其上傳到服務器的應用程序。手機將保存生成的ID。使用phonegap構建的相機不工作

我做了一個類abstractApp,它創建了一個App對象與幾個助手和變量。我正在使用Framework7。

var App; 


document.addEventListener("deviceready", function() { 
App = new abstractApp(); 
var i; 

App.f7Ref = new Framework7({init: false}); 

for (i = 0; i < App.constants.views.length; i++) 
{ 
    if (i==0) 
     App.mainView = App.f7Ref.addView (
      App.constants.views[i].selector, 
      App.constants.views[i].settings); 

    else 
     App.f7Ref.addView (
      App.constants.views[i].selector, 
      App.constants.views[i].settings); 

} 

// Checks if there exists register of remote photos 
if (App.local.get('remotephotos', false) == null || App.local.get('remotephotos', false) == '') 
{ 
    App.remotephotos = []; 
    App.local.set('remotephotos', []); 
} 
else 
{ 
    App.remotephotos = App.local.get('remotephotos'); 
} 

// Checks if there exists register of local photos 
if (App.local.get('localphotos', false) == null || App.local.get('localphotos', false) == '') 
{ 
    App.localphotos = []; 
    App.local.set('localphotos', []); 
} 
else 
{ 
    App.localphotos = App.local.get('localphotos'); 
} 


for (i = 0; i < appControllers.length; i++) 
{ 
    appControllers[i].apply(App); 
} 

console.log(App); 

}, false); 

在appControllers中,我保存了與每個頁面相關的功能(所以它更加有組織)。只有索引和新照片控制器我沒有問題,我可以將事件附加到元素並在視圖之間導航。問題在於調用相機對象。

window.appControllers.push(function() 
{ 
    var $$  = Dom7; 
    var Ref  = this.f7Ref; 
    var server = new serverInterface(); 
    var photos = this.remotephotos; 

    var App = this; 

    Ref.onPageInit('new', function (page) { 
     Ref.alert('entra', 'entra'); 
     $$('.capture').on('click', function() { 

     Ref.alert('Click', 'Click detected'); 

     navigator.camera.getPicture(onSuccess, onFail, 
     { 
      quality: 20, 
      destinationType: destinationType.FILE_URI 
     }); 

     function onSuccess(imageURI) { 
      Ref.alert('Photo captured.', 'Bien'); 
     } 

     function onFail(message) { 
      Ref.alert('There was a problem.', 'Ups'); 
     } 


     }); 
    }); 




}); 

所以,我進入新的一頁,我點擊與中國社會科學院捕獲和警告(點擊檢測)出現的按鈕,但它並不顯示相機拍攝的照片。

我正在使用Phonegap Build和一個android手機,你對發生了什麼有什麼想法嗎?

非常感謝您提前

回答

0

問題不在於我引用的JavaScript代碼。

我裝攝像頭插件在config.xml這樣

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

但要加載這樣:

<plugin name="cordova-plugin-camera" /> 

如果插件裝入不正確,在建的PhoneGap出現:安裝了版本n/a。在這種情況下,當它被正確加載時,出現:安裝版本2.1.0。

關於這個主題的更多信息可以在這裏找到:http://phonegap.com/blog/2015/11/19/config_xml_changes_part_two/

希望它可以幫助別人太

問候