IOS Base64 transcoding (using the IOS7 system comes with a coded library and GMTBase64 two different ways)

Source: Internet
Author: User


Demo:http://pan.baidu.com/s/1i3lvadz
The system provides a Base64 transcoding method in IOS7

Examples are as follows:

nsdata* origindata = [originstrdatausingencoding:nsasciistringencoding];

nsstring* encoderesult = [Origindatabase64encodedstringwithoptions: Nsdatabase64encodingendlinewithlinefeed];

NSLog (@ "encoderesult:%@", Encoderesult);


nsdata* decodedata = [[nsdataalloc] initwithbase64encodedstring: Encoderesult options:0];

nsstring* decodestr = [[nsstringalloc] initwithdata :d ecodedataencoding:nsasciistringencoding];



IOS uses open Source Library GTMBase64 transcoding

/**

*gtm transcoding

*/

-(void) gtmencodetest

{

nsstring* originstr = @ "man";

nsstring* encoderesult = nil;

nsdata* origindata = [originstrdatausingencoding:nsutf8stringencoding];

nsdata* encodedata = [GTMBase64encodedata: Origindata];

Encoderesult = [[nsstringalloc] initwithdata: Encodedataencoding: nsutf8stringencoding];

NSLog (@ "%@", Encoderesult);

}


/**

* GTM decoding

*/

-(void) gmtdecodetest

{

nsstring* encodestr = @ "Twfu";

nsstring* decoderesult = nil;

nsdata* encodedata = [encodestrdatausingencoding:nsutf8stringencoding];

nsdata* decodedata = [GTMBase64decodedata: Encodedata];

Decoderesult = [[nsstringalloc] initwithdata:d ecodedataencoding: nsutf8stringencoding];

NSLog (@ "%@", Decoderesult);

}






IOS Base64 transcoding (using the IOS7 system comes with a coded library and GMTBase64 two different ways)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.