0

phonegap バージョン 3 を使用しています。

cordova と phonegap をインストールしましたが、何らかの理由でコンソールに phonegap.js と cordova.js の読み込みに失敗したことが表示されます。それらは私のjsフォルダーにもないので、かなり奇妙だと思いましたが、今日カメラAPI機能を使用しようとするまで、phonegapは常に機能していました。カメラのプラグイン インストール コマンドを実行し、これを config.xml ファイルに追加しました。

<feature name="Camera">
    <param name="ios-package" value="CDVCamera" />
</feature>

ただし、カメラは iOS エミュレーターでは機能せず、Web ブラウザーでも機能しません。Web コンソールでこれらのエラーが発生しています。

Failed to load resource: The requested URL was not found on this server: file:///Users/thomas/dev/myapp/www/cordova.js

ボタンのいずれかをクリックすると、エラーが発生します

TypeError: 'undefined' is not an object (evaluating 'navigator.camera.getPicture')

これが私のコードです:(phonegap Webサイトから直接コピー)

<!DOCTYPE html>
<html>
  <head>
    <title>Capture Photo</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready",onDeviceReady,false);

    // device APIs are available
    //
    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoDataSuccess(imageData) {
      // Uncomment to view the base64-encoded image data
      // console.log(imageData);

      // Get image handle
      //
      var smallImage = document.getElementById('smallImage');

      // Unhide image elements
      //
      smallImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // Uncomment to view the image file URI
      // console.log(imageURI);

      // Get image handle
      //
      var largeImage = document.getElementById('largeImage');

      // Unhide image elements
      //
      largeImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      largeImage.src = imageURI;
    }

    // A button will call this function
    //
    function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

    // Called if something bad happens.
    //
    function onFail(message) {
      alert('Failed because: ' + message);
    }

    </script>
  </head>
  <body>
    <button onclick="capturePhoto();">Capture Photo</button> <br>
    <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
    <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    <img style="display:none;" id="largeImage" src="" />
  </body>
</html>
4

3 に答える 3

0

wwwフォルダーの正しい構造が欠けていると思います。現在、私は名前を正確に確認するためにオフィスにいませんが、

<root_folder_name> / wwww
               index.html
                     /camera
                             index.html 
                  /plugins
                         /<camera plugin name>
                                               /test
                  /platform
                       /ios
                           /<projectname>.xcodeproj

または同様の構造を持っている必要があります。とにかく、から: とフォルダーを別のフォルダーと一緒にルートフォルダーにplugins / <camerapluginmane> /test/ コピーします。index.htmlcameraindex.htmlwww

main.cssaも必要でmain.jscordova-incl.jsすべてのファイルは test フォルダーにあります。

/test/index.html ソースを再確認し、その構造とファイルを www ルート フォルダーで利用できるようにします。

明日か月曜日にオフィスに来て、この回答を編集し、名前を修正できます。

あなたのエラー:「TypeError: 'undefined' はオブジェクトではありません ('navigator.camera.getPicture' を評価しています'」それは Web パーツ (www 構造) にあり、コード呼び出しは ios ファイル ( .h .m ) にまだ行きませんでした) !

それが役立つことを願っています!

于 2013-08-23T17:29:28.807 に答える
0

この質問に答えるには遅すぎることはわかっていますが、実際の例に遅れはありません。以下のコードは私のために働いた。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

  <title>Camera Demo</title>
  <link rel="stylesheet" type="text/css" href="css/style.css" />
  <script src="js/jquery-1.11.3.min.js"></script>

  <script type="text/javascript">

    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value
    // Wait for Cordova to load
    document.addEventListener('deviceready', onDeviceReady, false);

    // Cordova is ready
    function onDeviceReady() {
      pictureSource=navigator.camera.PictureSourceType;
      destinationType=navigator.camera.DestinationType;
    }


    // Called when a photo is successfully retrieved  
    function onPhotoDataSuccess(imageData) {
      // Uncomment to view the base64-encoded image data
       console.log("  "+imageData);

      // Get image handle
      //
      var smallImage = document.getElementById('smallImage');

      // Unhide image elements
      //
      smallImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // Uncomment to view the image file URI
     //  console.log("IMAGE PATH: "+imageURI);
      alert("Image Url : "+imageURI);
      // Get image handle
      //
      var largeImage = document.getElementById('largeImage');

      // Unhide image elements
      //
      largeImage.style.display = 'block';



      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      largeImage.src = imageURI;
    }

    // A button will call this function
    //
    function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

    // Called if something bad happens.
    //
    function onFail(message) {
      alert('Failed because: ' + message);
    }
  </script>
</head>
<body>  
<header class="header">
<div class="header-div">
  <div class="header-single">
    <span id="title">Details </span>
  </div>
</div>
</header>
<div class="clear">
</div>
<content class="content-style">
 <h2> Camera Demo</h2>

  <button class="demo-btn-style" onclick="capturePhoto();">Capture Photo</button> <br>
  <button class="demo-btn-style" onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
  <button class="demo-btn-style" onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
  <button class="demo-btn-style" onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
  Small image: <br>
  <img style="display:none;width:100px;height:100px;" id="smallImage" src="" /> <br>
  Large image: <br>
  <img style="display:none;" id="largeImage" src="" /> <br>

</content>

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>

</boyd>
</html>
于 2016-03-03T07:02:54.887 に答える
0

ターミナルで、アプリのメイン フォルダーでcordova plugin add cordova-plugin-camera. PhoneGap を使用してブラウザにインストールしましたが、XCode によって作成された iOS バージョン用にインストールするには、これを再度行う必要があったようです。

Plugin "cordova-plugin-camera" already installed on browser. Installing "cordova-plugin-camera" for ios

これにより、.h ファイルと .m ファイルがプラットフォーム -> ios -> APPNAME -> plugins フォルダーに追加されました。

それは今すべて働いています!

于 2016-09-29T02:40:05.217 に答える