Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDWebImage setImageWithURL iOS8 crash

I've been using SDWebImage successfully for long. But with iOS8 its crashing when we set image i.e.

[ myImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",@"url"]] placeholderImage:[UIImage imageNamed:PROFILE_HOLDER_IMAGE]];

Is there way to avoid it

Cheers

like image 420
Mann Avatar asked Sep 15 '14 12:09

Mann


3 Answers

They have changed setImageWithURL to sd_setImageWithURL for iOS 8.

Try this new syntax,

[myImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",@"url"]] placeholderImage:[UIImage imageNamed:PROFILE_HOLDER_IMAGE]];
like image 122
VNAIK Avatar answered Oct 23 '22 06:10

VNAIK


First of all setImageWithURL:placeholderImage: is deprecated, also you must check if your URL string is not null. Try this approach:

    NSString *imageURLString;

    if (imageURLString && ![imageURLString isEqual:[NSNull null]])
    {
        NSURL *imageURL = [NSURL URLWithString:imageURLString];
        [myImageView sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    }

Also make sure that you use the latest version of SDWebImage.

like image 1
iOS Dev Avatar answered Oct 23 '22 07:10

iOS Dev


Some issues arise when using SDWebImage with iOS8 alongside with the crash, even when upgrading to the latest 3.7.1 version. A quick fix I found is to add the libPods-SDWebImage.a to the list of the linked binaries of the project (Select your project target > Build Phases > Link Binary With Libraries > click the '+' and add libPods-SDWebImage.a).

This is a fix for cocoapods users.

like image 1
Malloc Avatar answered Oct 23 '22 05:10

Malloc