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