【问题标题】:iPad app crashes when downloading files to the device将文件下载到设备时 iPad 应用程序崩溃
【发布时间】:2012-03-16 07:57:32
【问题描述】:

我有一个 iPad 应用程序,可以从后端下载视频、图像和 pdf 文件,但一段时间后(下载 400 mb 后)应用程序崩溃,控制台将 gdb 打印回来。下

这是我用于视频文件的写入功能的一部分。

更新

如果我释放 NSData 对象“mediaDataResponse”,应用程序会下载所有文件,但在下载所有文件后给我一个 EXC_BAD_ACCES 错误。

有什么帮助吗?

                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
                NSString *docsPath = [paths objectAtIndex:0]; 
                NSString *imageCacheDirPath = [docsPath stringByAppendingPathComponent:@"video"];

                if (![[NSFileManager defaultManager] fileExistsAtPath:imageCacheDirPath])
                {
                    [[NSFileManager defaultManager] createDirectoryAtPath:imageCacheDirPath 
                                              withIntermediateDirectories:NO 
                                                               attributes:nil
                                                                    error:NULL];
                }

                NSString *filename = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/video/%@.%@",cacheFileName,extensionstring]];
                [mediaDataResponse writeToFile:filename options: NSDataWritingAtomic error: &error];

                //Thumbnail
                NSArray *thumbpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
                NSString *thumbdocsPath = [thumbpaths objectAtIndex:0]; 
                NSString *thumbimageCacheDirPath = [thumbdocsPath stringByAppendingPathComponent:@"thumbnail"];

                if (![[NSFileManager defaultManager] fileExistsAtPath:thumbimageCacheDirPath])
                {
                    [[NSFileManager defaultManager] createDirectoryAtPath:thumbimageCacheDirPath 
                                              withIntermediateDirectories:NO 
                                                               attributes:nil
                                                                    error:NULL];
                }

                NSURL  *thumburl = [NSURL URLWithString:media.mediaThumbnail];
                NSData *thumburlData = [NSData dataWithContentsOfURL:thumburl];

                NSString *thumbfilename = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/thumbnail/%@.jpg", thumbcacheFileName]];
                [thumburlData writeToFile:thumbfilename options: NSDataWritingAtomic error: &error];

            }

当您在崩溃后启动应用程序时,它会继续下载它停止的位置。有人有同样的问题吗?提前致谢。

【问题讨论】:

  • 您能否提供有关崩溃报告的详细信息?
  • 让我看看能否找到崩溃报告的更多细节。
  • 还有一个细节。我在下载文件时也遇到了这个错误。 “SendDelegateMessage(NSInvocation*): delegate (_selectionLayoutChangedByScrolling:) 等待 10 秒后返回失败。主运行循环模式:_kCFURLConnectionPrivateRunLoopMode” 可能与问题有关。
  • 我也收到了。 3 月 16 日 09:53:56 未知 ReportCrash[867] :使用 uid:0 gid:0,synthetic_euid:0 egid:将 crashreport 保存到 /Library/Logs/CrashReporter/LowMemory-2012-03-16-095356.plist: 0

标签: ios ipad download gdb nsdata


【解决方案1】:

我认为您可能正在尝试将所有 400MB 的文件加载到内存中(基于 NSData 使用情况),这可能不是正确的方法(您的LowMemory 评论证实了这一点)。您可能希望拥有自己的 NSURLConnection 委托,该委托在收到响应时打开文件,并将所有字节直接附加到该文件(而不是将其保存在 NSData 中)。

【讨论】:

  • 我已经在尝试构建类似的东西,我会尝试一下!感谢您的回答!
猜你喜欢
  • 1970-01-01
  • 2018-10-23
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 2011-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多