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的只是空白,我没有错误在控制台中。
我真的很感谢你们给我的任何帮助。谢谢!