Appcelerator 应用程序在下载大型 (>500mb) zip 文件时崩溃

Appcelerator App crashes when downloading large (>500mb) zip file

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

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

通过 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();

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

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