我们直接在.m文件的引用头文件部分 和 @interface AddPictureViewController ()
之间 加入 增加部分的代码
然后就可以使用图片转Base64了
#import "AddPictureViewController.h"
#import <QuartzCore/QuartzCore.h>
#import <QuartzCore/CoreAnimation.h>
#import <MobileCoreServices/UTCoreTypes.h>
1 @interface NSData (MBBase64) 2 3 + (id)dataWithBase64EncodedString:(NSString *)string; 4 - (NSString *)base64Encoding; 5 6 @end 7 static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 8 9 @implementation NSData (MBBase64) 10 11 + (id)dataWithBase64EncodedString:(NSString *)string { 12 if (string == nil) 13 [NSException raise:NSInvalidArgumentException format:@""]; 14 15 if ([string length] == 0) 16 return [NSData data]; 17 18 static char *decodingTable = NULL; 19 20 if (decodingTable == NULL) { 21 decodingTable = malloc(256); 22 if (decodingTable == NULL) 23 return nil; 24 memset(decodingTable, CHAR_MAX, 256); 25 NSUInteger i; 26 for (i = 0; i < 64; i++) 27 decodingTable[(short)encodingTable[i]] = i; 28 } 29 30 const char *characters = [string cStringUsingEncoding:NSASCIIStringEncoding]; 31 if (characters == NULL) 32 return nil; 33 char *bytes = malloc((([string length] + 3) / 4) * 3); 34 if (bytes == NULL) 35 return nil; 36 37 NSUInteger length = 0; 38 NSUInteger i = 0; 39 40 while (YES) { 41 char buffer[4]; 42 short bufferLength; 43 for (bufferLength = 0; bufferLength < 4; i++) { 44 if (characters[i] == '