SDWebImage崩溃我的应用程序“终止,因为没有系统应用程序”

时间:2015-08-29 01:35:38

标签: ios ipad memory sdwebimage

我使用SDWebImage api从服务器下载图像。

代码如下:

[cell.activityIndicator startAnimating];
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:resourceInfo.previewImageUrl]
                  placeholderImage:[UIImage imageNamed:@"default_image"]
                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                             [cell.activityIndicator stopAnimating];
                        }];

我使用UITableView或UICollectionView来显示图像。我的图像资源很大(超过2MB)。我监视内存使用情况,并没有快速增长。

我使用模拟器和代码运行良好,没有内存警告。

但是当我将我的项目部署到iPad(iOS 8.1)时,我的应用程序每次都崩溃(显示图像表视图时),我的iPad显示带有白色苹果徽标的黑屏。像启动屏幕,但只有几秒钟。然后iPad回到锁定屏幕。

日志窗口显示:“因为没有系统应用程序而终止”。有时还会显示内存警告信息。有时会导致信号SIGTERM。

我添加了“All Exceptions”断点,但从未调用过。

我还在didReceiveMemoryWarning

中添加了SDImageCache clear memory方法
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    SDImageCache *imageCache = [SDImageCache sharedImageCache];
    [imageCache clearMemory];
}

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。我只使用SDWebImageDownloader下载图像。然后我自己将图像保存到特殊位置。然后为原始图像生成一个快捷图像(压缩和调整大小),我在UIImageView中使用压缩图像,效果很好。所以&# 39;因为原始图像数据太大了。

UIImage *localImage = [[ImageResourceManager sharedInstance] getShortcutImage:currentResourceInfo.previewImageUrl];
if (localImage != nil) {
    cell.previewImageView.image = localImage;
}
else
{
    [cell.activityIndicator startAnimating];
    [SDWebImageDownloader.sharedDownloader downloadImageWithURL:[NSURL URLWithString:currentResourceInfo.previewImageUrl]
                                                        options:0
                                                       progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                                                       }
                                                      completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
                                                          if (image && finished) {
                                                              [[ImageResourceManager sharedInstance] storeImageToLocal:image
                                                                                                              imageUrl:currentResourceInfo.previewImageUrl];
                                                              if (self.viewModel.currentSelectResourceType == Picture) {
                                                                  dispatch_async(dispatch_get_main_queue(), ^{
                                                                      cell.previewImageView.image = [[ImageResourceManager sharedInstance] getShortcutImage:currentResourceInfo.previewImageUrl];
                                                                  });
                                                              }
                                                          }
                                                          [cell.activityIndicator stopAnimating];
                                                      }];
}