【发布时间】:2016-04-08 15:18:26
【问题描述】:
我们目前正在开发一个带有 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();
【问题讨论】:
-
你有崩溃日志吗?
-
@Shawn 感谢您的提问,miga 的回答解决了问题。
标签: ios iphone appcelerator appcelerator-titanium