我一直在疯狂地试图找出为什么我无法访问ios6模拟器上的文件内容,我试图将其作为我的iframe中的ng-src链接。
我目前正在使用ngCordova $ cordovaFileTransfer,$ cordovaFile,& $ cordovaZip插件下载外部资源,将其解压缩到文件系统上的某个位置,然后更新iframe的src以反映新内容。
我不确定在使用模拟器的文件系统时是否遗漏了一些基本的知识,但我已经完全碰壁了。以下是我的观点代码:
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);
};
}
这是我的控制器的相关部分:
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
有人可以解释为什么我无法从本地设备访问该文件吗?当我在console.log文件路径中,我得到这样的东西:
[self.tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
即使我尝试直接链接到文件,iframe也只是空白,我在控制台中没有错误。
我非常感谢你们给我的任何帮助。三江源!