【问题标题】:How to use phonegap-1.3.0.js in xcode 5.1.1 for camera functions如何在 xcode 5.1.1 中使用 phonegap-1.3.0.js 进行相机功能
【发布时间】:2014-07-02 04:02:08
【问题描述】:

通过使用 phonegap 和 XCode,我为 iPad 开发了一个 iOS 应用程序。通过将 phonegap 1.3.0.js 与 XCode 4.3 一起使用,我已经完成了图像捕获相机和 ipad 相册中的图像选择。

主要问题是我已将 X Code 版本更新为 X Code 5.1.1 并在我的 MAC MINI 中安装了 phone gap 2.9.1 版本。但是当我在 ipad2 中测试应用程序时,图像捕获和图像选择不起作用。作为 X Code 电话间隙的新手,我无法确定它发生的问题。现在我正在使用内置在 phone gap 2.9.1 中的 cordova .js。

JavaScript 函数正在调用,但语法

navigator.camera. get Picture(); 来自该行。

我使用的代码如下

var imageLength = 0;

function take Picture() {
    navigator.camera.get Picture()
};

你能帮我解决它吗?

【问题讨论】:

    标签: javascript ios xcode cordova


    【解决方案1】:

    试试这个

    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(imageURI) {
        alert("fire");
        // Uncomment to view the base64-encoded image data
        console.log(imageURI);
        // Get image handle
        //
        var cameraImage = document.getElementById('image');
        // Unhide image elements
        //
        cameraImage.style.display = 'block';
        // Show the captured photo
        // The inline CSS rules are used to resize the image
        //
        cameraImage.src = imageURI;
    }
    // Called when a photo is successfully retrieved
    //
    
    function onPhotoURISuccess(imageURI) {
        alert("fire");
        // Uncomment to view the image file URI
        console.log(imageURI);
        // Get image handle
        //
        var galleryImage = document.getElementById('image');
        // Unhide image elements
        //
        galleryImage.style.display = 'block';
        // Show the captured photo
        // The inline CSS rules are used to resize the image
        //
        galleryImage.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: 30,
            targetWidth: 600,
            targetHeight: 600,
            destinationType: destinationType.FILE_URI,
            saveToPhotoAlbum: true
        });
    }
    // A button will call this function
    //
    
    function getPhoto(source) {
        // Retrieve image file location from specified source
        navigator.camera.getPicture(onPhotoURISuccess, onFail, {
            quality: 30,
            targetWidth: 600,
            targetHeight: 600,
            destinationType: destinationType.FILE_URI,
            sourceType: source
        });
    }
    // Called if something bad happens.
    //
    
    function onFail(message) {
        //alert('Failed because: ' + message);
    }
    

    你可以在这里下载我的示例代码:https://github.com/datomnurdin/com.revivalx.cordova.camera

    【讨论】:

    • 首先感谢您的回复。主要问题是当我调用它正在调用但在 navigator.camera.getPicture() 处停止的 javascript 函数时。在该语法之后,我没有得到任何回应。供您参考,我正在使用 PhoneGap 2.9.1 、 codova 3.5.0 XCode 5.1.1。我已将最新的 cordova.js 文件放在 www 文件夹中,并在 index.html 文件中给出了完美的路径。你能建议我如何使用带有Phonegap 2.9.1 的XCode 5.1.1 的cordova.js
    • 嗨 Mohammad 你能告诉我如何根据cordova 3.5.0版本使用这个功能
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 2021-02-20
    • 2012-09-23
    • 1970-01-01
    • 2020-12-12
    相关资源
    最近更新 更多