在PhoneGap中添加文件传输会导致构建失败。

3
我正在尝试在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个回答

1
这似乎与整个PhoneGap/Cordova有关。使用Cordova而不是PhoneGap创建新项目可以解决该问题。如果使用PhoneGap启动应用程序,则似乎FileTransfer API存在问题。

我遇到了同样的问题 - 我删除了“file”插件,“file-transfer”插件,然后重新添加它们,一切都正常了。 - medvedNick

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接