0

我已经从 Phonegap 1.5.0 更新到 2.0.0,面临下载问题。

这是我的下载功能:

function download(){
var ecodedurl = "http://finance.yahoo.com/d/quotes.csv?s=^NSEI+^NSEBANK&f=pl1";
      var remoteFile = encodeURI(ecodedurl);
      var localFileName = "temp.txt";
      var attachmentFileName = localFileName;
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
      fileSystem.root.getDirectory("Temp", {create: true, exclusive: false}, function(directoryEntry) {
       directoryEntry.getFile(localFileName, {create: true, exclusive: false}, function(fileEntry) {
        var localPath = fileEntry.fullPath;
       if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
         localPath = localPath.substring(7);
                  }
                       var ft = new FileTransfer();
                     ft.download(remoteFile,
              localPath, function(entry) {
                           attachmentFileEntry = entry;
                 loadFileData(attachmentFileEntry);
                                                                                               }, fail);
                                                                                   }, fail);
                                                            }, fail);
                               }, fail);
      function fail(error) {
          //console.log(error.code);
          //alert("Error occured while downloading the attachment");
          navigator.notification.alert('Error occured while downloading the attachment. Please try again', alertConfirm);
      }

  }

  }

function loadFileData(allText) {
    console.log("loadFileData method:"+allText);
    console.log("allText URL:"+allText.toURL());
    var fileURL = allText.toURL().substring(7);
    console.log("URL:"+fileURL);
    $.ajax({
           type: "GET",
           url: fileURL,
           dataType: "text",
           success: function(data) {
           console.log("file loaded");
           processData(data);}
           });

获取文件传输错误:源 URL 不在白名单中:http: //finance.yahoo.com/d/quotes.csv? s= ^NSEI+^NSEBANK&f=pl1

已尝试将其包含在 phonegap.xml 文件中...它可以正常工作:(

4

1 回答 1

0

如果是用于 iPhone 应用程序,则需要编辑 Cordova.plist,它在 xcode 中位于 Resources 下。编辑它(最好通过 xcode xml 编辑器 - 即只需单击它)。在 Extenrnal Hosts 下添加字符串项。在值上,设置您的站点,或 * 用于任何外部站点。

于 2012-09-17T08:30:41.173 回答