Reputation: 31
I am trying to build in xcode but I keep getting this issue
No visible @interface for 'NSData' declares the selector 'initWithBase64Encoding:'
and
No visible @interface for 'NSData' declares the selector 'base64Encoding'
I have looked everywhere not but there isn't a clear solution to my problem. These are what's giving me problem:
- (NSString*)stringFromImage:(UIImage*)image
{
if(image)
{
UIImage* convertImage = [GameUtility imageWithImage:image scaledToSize:CGSizeMake(80, 80)];
NSData *dataObj = UIImageJPEGRepresentation(convertImage, 30);
return [dataObj base64Encoding];
}
return @"";
}
- (UIImage*)imageFromString:(NSString*)imageString
{
NSData* imageData =[[NSData alloc] initWithBase64Encoding:imageString];
return [UIImage imageWithData:imageData];
}
Upvotes: 0
Views: 2477
Reputation: 803
use this base64 file for encode and decode
- (NSString*)stringFromImage:(UIImage*)image
{
if(image)
{
UIImage* convertImage = [GameUtility imageWithImage:image scaledToSize:CGSizeMake(80, 80)];
NSData *dataObj = UIImageJPEGRepresentation(convertImage, 30);
return [dataObj base64EncodedString];
}
return @"";
}
- (UIImage *)imageFromString:(NSString*)imageString
{
NSData* imageData =[imageString base64DecodedData];
return [UIImage imageWithData:imageData];
}
Upvotes: 1
Reputation: 134
You can convert your image to string like this first. And then you can try convert your UIImage
to NSData
& then convert that data into string by using encodeBase64WithData
NSString * Image = [self encodeBase64WithData:[imageDict objectForKey:@"Image"]];
and then try your UIImage
to string like this
[UIImage imageWithData: [self decodeBase64WithString:[registerDataDict objectForKey:@"Image"]]];
Hope it helps you
Upvotes: 1
Reputation: 95355
If you are targeting OS X 10.9 or iOS 7 you can use the base64EncodedStringWithOptions:
method to encode the string, and the initWithBase64EncodedString:options:
method to decode the string.
If you are targeting platforms earlier than this, you need to either write these methods yourself or find a library that implements them for you (as category methods of NSData
). Different libraries will have different names for these methods, so make sure you check with that library's documentation or check the header.
Upvotes: 1