Posts

Showing posts with the label objective-c

Base64 Images with Xamarin.IOS

Today I was adding the ability to render Base64 encoded image strings to my iOS application which is built using Xamarin.iOS. These images are just small thumbnails and are stored in a small database within my app. Since iOS 7 it's really easy to render these as UIImage's inside an UIImageView, in objective-c you simply do something along the lines of: NSData* data = [[NSData alloc] initWithBase64EncodedString:base64String options:0]; UIImage* image = [UIImage imageWithData:data]; With Xamarin.IOS this would translate to: var image = new NSData(base64image, NSDataBase64DecodingOptions.None); var uiImage = UIImage.LoadFromData(image); However running this gives you the following exception: System.Exception: Could not initialize an instance of the type 'MonoTouch.Foundation.NSData': the native 'initWithBase64EncodedData:options:' method returned nil. Ouch As this exception is within the NSData class which is a class that Xamarin generates to map...