Search code examples
iosencodinguiimagebase64encode

Encode UIImage to base64 string on iOS


I have a problem with encoding UIImage to the base64 string using this category.

This is the code:

NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"myImage.png"], 1.0);
NSString *imageString = [imageData base64EncodedString];

I get this error:

-[NSConcreteData base64EncodedString]: unrecognized selector sent to instance 0x906800 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteData base64EncodedString]: unrecognized selector sent to instance 0x906800'

I just cannot figure it out where the problem is? Can anyone help me with this?

Thanks!


UPDATE

I just figured it out. Xcode did not put .m file into Compile Sources und project Build Phases. Why is this happening all the time on Xcode 4.3 ?


Solution

  • Xcode did not put .m file into Compile Sources under project Build Phases. This happened cos I was not careful choosing the right target (project/test).