Search code examples
iosbase64nsdatadecode

Decode base64 string for image


I have encoded string in base64 and want to decode it but getting nil in NSData *decodedData. NSString *images contains encoded string.

NSString *images = encoded string;
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:images options:0];
UIImage *myImage = [UIImage imageWithData:decodedData];

Solution

  • Perhaps you have unknown characters? Try passing NSDataBase64DecodingIgnoreUnknownCharacters into the options: parameter.