繁体   English   中英

下载图像时iPhone4s中的应用程序崩溃

[英]App crash in iPhone4s while downloading images

我正在使用SDWebImage从服务器异步下载图像。 我已经在iOS 8.1 iPhone 5和5s上测试了该应用程序,并且工作正常,完全没有内存警告。但是我给客户端建立了版本(使用iPhone 4s),但是在加载图像时他遇到了一些崩溃,不幸的是我没有iPhone 4s无法解决问题。 我在iPhone5的乐器上进行了测试,这是几次运行后的屏幕截图。 使用iPhone 5截屏 这是我的下载图像代码

-(void)setImageWithUrl:(NSURL*)imgurl onImageView:(UIImageView*)image prograssive:(BOOL)progressive
{

    __block UIActivityIndicatorView *activityIndicator;

    __weak UIImageView *weakImageView = image;

    SDWebImageOptions opt;
    if (progressive) {

        opt = SDWebImageProgressiveDownload;
    }
    else
        opt = SDWebImageRetryFailed;

    [image sd_setImageWithURL:imgurl placeholderImage:[UIImage imageNamed:@"default_image"] options:opt progress:^(NSInteger receivedSize, NSInteger expectedSize)
     {
         if (!activityIndicator)
         {
             [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
             activityIndicator.center = CGPointMake(weakImageView.frame.size.width /2, weakImageView.frame.size.height/2);
             // activityIndicator.center = weakImageView.center;
             [activityIndicator setBackgroundColor:[UIColor clearColor]];
             [activityIndicator startAnimating];

         }
     }
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
     {

         [activityIndicator removeFromSuperview];
         activityIndicator = nil;
     }];
}

我确实在didRecdeiveMemoryWarnig方法中清除了内存

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSLog(@"memory warning received in voucher");
    [[SDImageCache sharedImageCache] clearMemory];
    [[SDImageCache sharedImageCache] cleanDisk];
    [[SDImageCache sharedImageCache] setValue:nil forKey:@"memCache"];
}

但是它仍然在iPhone 4s中崩溃,有人可以指导我做什么吗?

听起来您的应用程序由于内存压力而被杀死。 也许尝试使用自动释放池来缓解任何内存高峰,因为我认为您在didReceiveMemoryWarning中所做的事情在这种情况下并没有真正的帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM