2015-10-13 79 views
2

我一直瘋了,試圖找出爲什麼我不能訪問我試圖鏈接的ios6模擬器上的文件的內容我的iframe中的ng-src。Ionic科爾多瓦AngularJS - 無法訪問文件:/ /在iframe

我目前使用ngCordova $ cordovaFileTransfer,$ cordovaFile,& $ cordovaZip插件下載外部資源,將其解壓縮到文件系統的某個位置,然後更新iframe的src以反映新內容。

我不確定在使用模擬器的文件系統時是否缺少一些基本知識,但是我已經完全打開了牆。下面是我的看法代碼:

<ion-view view-title="{{course.title}}" class="single-course"> 

    <ion-content> 
    ... 
    <iframe id="course-iframe" width="100%" height="100%" ng-src="{{courseData | trustAsResourceUrl}}"/></iframe> 
    ... 
    </ion-content> 
</ion-view> 

這裏是一塊有關我的控制器:

function SingleCourseCtrl($scope, $stateParams, $cordovaZip, $timeout, $ionicPlatform, $cordovaFile, $cordovaFileTransfer, ModalService, Courses) { 


    // Initialize some variables on start 
    $scope.downloading = false; 
    $scope.fileURL = ''; 
    $scope.progress = 0; 
    $scope.courseData = ''; 

    $scope.download = function() { 
    $scope.downloading = true; 

    // Make sure the device is ready in order to start 
    document.addEventListener('deviceready', function() { 

     var url = "[link-to-download-file]"; 

     // Check to see if the file exists in "Documents" 
     var courseDir = "courses/course-" + $scope.course.id; 
     $cordovaFile.checkFile(cordova.file.documentsDirectory, courseDir); 

     // Check to see if courses directory exists 
     // If not, create "courses" directory in "Library" 
     $cordovaFile.checkDir(cordova.file.dataDirectory, courseDir). 
     then(function(success) { 
     }, function(error) { 
      $cordovaFile.createDir(cordova.file.dataDirectory, courseDir, false) 
      .then(function(success) { 
       console.log(JSON.stringify(success)); 
      }); 
     }); 

     // Create the target filename, based on course id 
     var targetPath = cordova.file.documentsDirectory + '/' +courseDir + ".zip", 
      trustHosts = true, 
      options = {}; 

     // Download the file to the device 
     $cordovaFileTransfer.download(url, targetPath, options, trustHosts) 
     .then(function(result) { 

      $scope.downloading = false; 

      // Once downloaded, unzip the contents of the zip to the appropriate directory 
      $cordovaZip 
      .unzip(
       targetPath, 
       cordova.file.dataDirectory + courseDir 
      ).then(function() { 

       // Set the index file of the course 
       $scope.courseData = cordova.file.dataDirectory + courseDir + '/a001index.html'; 


      }); 
     }, function(err) { 
      // Error 
     }, function (progress) { 
      // Show loading bar 
      $scope.progress = Math.round((progress.loaded/progress.total) * 100); 
      $scope.courseLoaded = progress.loaded; 
      $scope.courseTotal = progress.total; 
     }); 


     }, false); 
    }; 
    } 

任何人都可以提供一些線索,爲什麼我不能從本地訪問該文件設備?當我CONSOLE.LOG文件路徑,我得到的是這樣的:

file://Users/Stevie/Library/Developer/CoreSimulator/Devices/70EA2E87-A715-4252-B5B8-A5C03E090BD9/data/Containers/Data/Application/108F6AE2-3A24-4F86-AF19-1DC50E85AEF2/Library/NoCloud/courses/course-0/a001index.html 

即使我嘗試鏈接到該文件直接,iframe的只是空白,我沒有錯誤在控制檯中。

我真的很感謝你們給我的任何幫助。謝謝!

回答