ios - 将文件下载到设备时 iPad 应用程序崩溃
<p><p>我有一个 iPad 应用程序,可以从后端下载视频、图像和 pdf 文件,但一段时间后(下载 400 mb 后)应用程序崩溃并且控制台将 gdb 打印回来。下</p>
<p>这是我用于视频文件的写入功能的一部分。</p>
<p><em>更新</em></p>
<p>如果我释放 NSData 对象“mediaDataResponse”,应用程序会下载所有文件,但在下载所有文件后给我一个 EXC_BAD_ACCES 错误。</p>
<p>有什么帮助吗?</p>
<pre><code> NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = ;
NSString *imageCacheDirPath = ;
if (![ fileExistsAtPath:imageCacheDirPath])
{
[ createDirectoryAtPath:imageCacheDirPath
withIntermediateDirectories:NO
attributes:nil
error:NULL];
}
NSString *filename = ];
;
//Thumbnail
NSArray *thumbpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *thumbdocsPath = ;
NSString *thumbimageCacheDirPath = ;
if (![ fileExistsAtPath:thumbimageCacheDirPath])
{
[ createDirectoryAtPath:thumbimageCacheDirPath
withIntermediateDirectories:NO
attributes:nil
error:NULL];
}
NSURL*thumburl = ;
NSData *thumburlData = ;
NSString *thumbfilename = ];
;
}
</code></pre>
<p>当您在崩溃后启动应用程序时,它会继续下载它停止的位置。有人有同样的问题吗?提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您可能正在尝试将所有 400MB 的文件加载到内存中(基于 NSData 使用情况),这可能不是正确的方法(您的 <code>LowMemory</code> 评论证实了这一点)。您可能希望拥有自己的 NSURLConnection 委托(delegate),该委托(delegate)在收到响应时打开文件,并将所有字节直接附加到该文件(而不是将其保存在 NSData 中)。</p></p>
<p style="font-size: 20px;">关于ios - 将文件下载到设备时 iPad 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/9733729/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/9733729/
</a>
</p>
页:
[1]