gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:57:12 25 4
gpt4 key购买 nike

我们目前正在开发一个带有 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();

最佳答案

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com