在PhoneGap中添加filetransfer会破坏构建

时间:2014-02-14 00:04:21

标签: ios cordova phonegap-plugins

我正在尝试将视频上传到PhoneGap中的服务器。代码在打开相机对话框和录制视频方面运行,但是index.html文件中的JS需要使用FileTransfer插件。

从phonegap命令行添加此插件会导致以下错误...

/platforms/ios/ManUtd/Plugins/org.apache.cordova.file-transfer/CDVFileTransfer.m:23:9:找不到'CDVLocalFilesystem.h'文件

html文件是来自PhoneGap网站的文档化代码

<!DOCTYPE html>
<html>
<head>    
<title>Capture Video</title>    
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

        // Called when capture operation is finished
        //
        function captureSuccess(mediaFiles) {
            var i, len;
            for (i = 0, len = mediaFiles.length; i < len; i += 1) {
                uploadFile(mediaFiles[i]);
            }
        }

    // Called if something bad happens.
    //
    function captureError(error) {
        var msg = 'An error occurred during capture: ' + error.code;
        navigator.notification.alert(msg, null, 'Uh oh!');
    }

    // A button will call this function
    //
    function captureVideo() {
        // Launch device video recording application,
        // allowing user to capture up to 2 video clips
        navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 2});
    }

    // Upload files to server
    function uploadFile(mediaFile) {
        var ft = new FileTransfer(),
        path = mediaFile.fullPath,
        name = mediaFile.name;

        ft.upload(path,
                  "http://my.domain.com/upload.php",
                  function(result) {
                  console.log('Upload success: ' + result.responseCode);
                  console.log(result.bytesSent + ' bytes sent');
                  },
                  function(error) {
                  console.log('Error uploading file ' + path + ': ' + error.code);
                  },
                  { fileName: name });   
    }

        </script>
</head>
<body>
    <button onclick="captureVideo();">Capture Video</button> <br>
</body>
</html>

我已经运行了这两个命令,两者都导致代码破坏

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git

我目前只针对iOS

1 个答案:

答案 0 :(得分:1)

这似乎与整个PhoneGap / Cordova有关。

使用Cordova而不是PhoneGap创建新项目已对问题进行了排序。如果您使用PhoneGap启动应用程序,则看起来好像FileTransfer API已损坏。