简体   繁体   English

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

[英]App crash in iPhone4s while downloading images

I'm using SDWebImage for asynchrony download images from server. 我正在使用SDWebImage从服务器异步下载图像。 I've tested the app in iPhone 5 and 5s with iOS 8.1 and working fine, no memory warning at all.But i given build to client(using iPhone 4s) and he faces some crash while loading images, unfortunately i don't have iPhone 4s so can't figure out the problem. 我已经在iOS 8.1 iPhone 5和5s上测试了该应用程序,并且工作正常,完全没有内存警告。但是我给客户端建立了版本(使用iPhone 4s),但是在加载图像时他遇到了一些崩溃,不幸的是我没有iPhone 4s无法解决问题。 I tested in instruments with iPhone5 and here is screen shots after several run. 我在iPhone5的乐器上进行了测试,这是几次运行后的屏幕截图。 使用iPhone 5截屏 And here is my code for download image 这是我的下载图像代码

-(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;
     }];
}

I did cleared memory in didRecdeiveMemoryWarnig method 我确实在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"];
}

But it still crashes in iPhone 4s.Can any one guid me what do? 但是它仍然在iPhone 4s中崩溃,有人可以指导我做什么吗?

It sounds like your App is being killed due to memory pressure. 听起来您的应用程序由于内存压力而被杀死。 Maybe try using an Autorelease Pool to mitigate any memory spikes, since I think what you are doing in didReceiveMemoryWarning doesn't really help in those situation. 也许尝试使用自动释放池来缓解任何内存高峰,因为我认为您在didReceiveMemoryWarning中所做的事情在这种情况下并没有真正的帮助。

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

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