如何在 iPhone 上进行 Base64 编码 [英] How to Base64 encoding on the iPhone
本文介绍了如何在 iPhone 上进行 Base64 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 iPhone 上进行 Base64 编码?
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.
推荐答案
可以看例子 这里.
适用于 iOS7+.
我把代码复制到这里,以防万一:
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);
这篇关于如何在 iPhone 上进行 Base64 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文