OGeek|极客世界-中国程序员成长平台

标题: ios - 下载大型 (>500mb) zip 文件时,Appcelerator 应用程序崩溃 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:51
标题: ios - 下载大型 (>500mb) zip 文件时,Appcelerator 应用程序崩溃

我们目前正在开发一个带有 Appcelerator 的 iOS 应用程序,它将媒体文件存储在设备上以供以后查看(pdf、mp4、压缩网页)。

我们现在面临一个问题,即超过 500MB 的文件会导致 iPhone 上的应用程序崩溃。该应用在 iPad2 上运行,但所有 iPhone 在下载这些文件时都经过测试(随机)崩溃。

文件通过 ti.compression 解压缩(所有媒体文件都在存档中附带附加信息)。

使用的代码是(分解为相关部分):

var zipDownloader = Ti.Network.createHTTPClient({
'onload' : function() {
    var tempname = Math.floor((Math.random() * 10000000) + 1);

    var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'tempDownloads', tempname);
    dir.createDirectory();

    filename = '' + tempname + '.zip';
    var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'tempDownloads', filename);
    f.write(this.responseData);
    var Compression = require('ti.compression');

    var zipFileName = Ti.Filesystem.applicationDataDirectory + 'tempDownloads/' + filename;
    var outputDirectory = Ti.Filesystem.applicationDataDirectory + 'tempDownloads/' + tempname + '/';
    var start = Math.floor(Date.now() / 1000);
    var result = Compression.unzip(outputDirectory, zipFileName, true);
    var finished = Math.floor(Date.now() / 1000) - start;
    f.deleteFile();
    Compression = null;
    this.callback(outputDirectory);
}
});
zipDownloader.open('GET', url);
zipDownloader.callback = callback; // given in previous code, not relevant
zipDownloader.send();



Best Answer-推荐答案


设置 HTTPClient ( https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient-property-file ) 的文件属性,而不是在下载文件后写入文件。

这适用于较大的文件,因为它将数据直接写入文件。否则它会先尝试缓存你的文件,你的应用可能会因为内存错误而崩溃。尝试了 500+MB 的文件

关于ios - 下载大型 (>500mb) zip 文件时,Appcelerator 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36503332/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4