IPhone object-C base64 encoding

Source: Internet
Author: User


Download the downloaded base64.zip file and compress it into your project.

Then we can write a method to call it. It is very simple. I encapsulate a class to do it myself. In this way, the functions in the library are more transparent to me, and of course not necessary. It can be used on my current machine. If you have any questions, please contact me.

//. H file, default
# Import <Foundation/Foundation. h>

@ Interface utility: nsobject {

}

+ (Nsstring *) encodebase64 :( nsstring *) input; + (nsstring *) decodebase64 :( nsstring *) input;

@ End

The above is the header file, and below is the code file. It is easy for me to write this method into any code.

# Import "utility. H"
// Use the header file
# Import "gtmbase64.h"

@ Implementation Utility

+ (Nsstring *) encodebase64 :( nsstring *) Input
{
Nsdata * Data = [input datausingencoding: nsutf8stringencoding allowlossyconversion: Yes];
// Convert to base64
Data = [gtmbase64 encodedata: Data];
Nsstring * base64string = [[nsstring alloc] initwithdata: data encoding: nsutf8stringencoding];
Return base64string;
} + (Nsstring *) decodebase64 :( nsstring *) Input
{
Nsdata * Data = [input datausingencoding: nsutf8stringencoding allowlossyconversion: Yes];
// Convert to base64
Data = [gtmbase64 decodedata: Data];
Nsstring * base64string = [[nsstring alloc] initwithdata: data encoding: nsutf8stringencoding];
Return base64string;
}

@ End

You can use encodebase64 to convert the string to base64 next time.

Base64.zip

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.