簡體   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