How to display a base64 image within a UIImageView?

You don’t have to encode it. Simply make a NSUrl, it knows the “data:”-url.

NSURL *url = [NSURL URLWithString:base64String];    
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *ret = [UIImage imageWithData:imageData];

As mentioned in the comments, you have to make sure that you prepend your data with data:image/png;base64, or else your base64 data is useless.

Leave a Comment