iPhone开发 – Obj-C Base64编码的方法

下载附件中的代码文件到您的项目中,然后照抄以下的封装函数:

+ (NSString*)encodeBase64:(NSData*)data
{
//转换到base64
data = [GTMBase64 encodeData:data];
NSString * base64String = [[NSString alloc] initWithData:data
     encoding:NSUTF8StringEncoding];
return base64String;
}

以上代码基本照抄JGuoer的,不过修改了一下,来实现自己的图像的Base64编码..
然后使用需要编码的时候很简单,把所需的数据作为参数代入即可.
需要说明的,如果是字符串,生成NSData的代码应按下面的格式写.

NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding
     allowLossyConversion:YES];

文件本地地址:base64.zip

文件Guoler地址:base64.zip

参考地址:
JGuoer:iPhone开发 – Object-c Base64编码问题

This entry was posted in 代码 人生 and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>