如何为Base64在iPhone上的编码 [英] How to Base64 encoding on the iPhone

查看:919
本文介绍了如何为Base64在iPhone上的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么办Base64编码的iPhone?

How do I do Base64 encoding on the iPhone?

我发现,看起来前途无量的几个例子,但永远无法得到任何人的手机上运行。

I have found a few examples that looked promising, but could never get any of them to work on the phone.

推荐答案

您可以看到一个例子的这里

You can see an example here.

这是iOS7 +

我在这里复制code,以防万一:

I copy the code here, just in case:

// Create NSData object
NSData *nsdata = [@"iOS Developer Tips encoded in Base64"
  dataUsingEncoding:NSUTF8StringEncoding];

// Get NSString from NSData object in Base64
NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];

// Print the Base64 encoded string
NSLog(@"Encoded: %@", base64Encoded);

// Let's go the other way...

// NSData from the Base64 encoded str
NSData *nsdataFromBase64String = [[NSData alloc]
  initWithBase64EncodedString:base64Encoded options:0];

// Decoded NSString from the NSData
NSString *base64Decoded = [[NSString alloc] 
  initWithData:nsdataFromBase64String encoding:NSUTF8StringEncoding];
NSLog(@"Decoded: %@", base64Decoded);

这篇关于如何为Base64在iPhone上的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆