1

ここでいくつかの同様の投稿を読んだことがありますが、成功しませんでした。やりたいことはシンプル。私は非常に小さなjqueryモバイルアプリを持っており、phonegapに包まれています。特定のページで、デバイスのカメラにアクセスできるようにしたい (iPhone としましょう)。phonegap camera docsのコードを使用しています

jquery モバイルを使用しない場合、コード自体は正しく機能しますが、JQM を使用してアプリのスタイルを設定したいと考えています。

JQM が ajax を使用してページを呼び出し、独自の pageinit() および pageshow() 関数があることは知っています。phonegap と JQM の両方が独自の関数を起動する必要があるため (deviceReady() と JQM はページを初期化する必要があるため)、両方をうまく連携させるにはどうすればよいですか。

それが役立つ場合、これはカメラページの私のコードです:

    <!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name = "format-detection" content = "telephone=no"/>
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width;" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.1.1.css" />
        <title>Take Picture</title>

    </head>
    <body>
        <div id="takePicturePage" data-role="page" data-add-back-btn="true">

            <div data-role="header" data-position="fixed" id="hrdHome" data-theme="b">
                <h1>Take a picture</h1>
            </div><!-- /header -->
            <div data-role="content" id="content">

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

            </div><!-- /content -->
         </div>

        <script type="text/javascript" src="cordova-2.0.0.js"></script>
        <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
        <script type="text/javascript" src="js/takePicture.js"></script>
    </body>
</html>

そして、これは私のtakePicture.jsです:

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

// Wait for PhoneGap to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);

// PhoneGap is ready to be used!
//
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 });
}

// 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 }); 
}

// 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);
}

2つがどのように連携できるかわかりませんので、誰か助けてください。

よろしくお願いします

4

3 に答える 3

2

そこにいる誰かにそれを使用する場合に備えて、このcordova-jquerymobile-boilerplateを使用することになりました。これは、治療を行い、すべての問題を解決しました。

于 2012-11-19T11:51:43.643 に答える
1

ここでそれについて知ることができますhttp://jquerymobile.com/test/docs/pages/phonegap.html

于 2012-07-30T06:26:31.270 に答える
1

あなたのjsは私にとって完璧に機能しています。JQM 1.2.0、コルドバ 2.0 を使用しています。deviceready を呼び出しているようには見えませんが、 body onload="onload" アプローチを試して、それが役立つかどうかを確認してください。

function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
于 2012-11-02T14:15:48.837 に答える