ios - 使用 ios8/ios9 api 的 base64 编码没有行长度限制

标签 ios objective-c ios8 base64 ios9

如何在没有行长度限制的情况下使用 ios8 和 ios9 api 对字符串进行 base64 编码。

我正在准备一些自定义的基本身份验证,我需要根据标准对凭证进行编码,这意味着:

然后使用 Base64 的 RFC2045-MIME 变体对生成的字符串进行编码,但不限于 76 个字符/行

在旧的 ios7 中有一个方法:NSData base64Encoding 但现在已弃用,取而代之的是:

- (NSString *)base64EncodedStringWithOptions:
(NSDataBase64EncodingOptions)options NS_AVAILABLE(10_9, 7_0);

选项是:

typedef NS_OPTIONS(NSUInteger, NSDataBase64EncodingOptions) {
// Use zero or one of the following to control the maximum line length after which a line ending is inserted. No line endings are inserted by default.
NSDataBase64Encoding64CharacterLineLength = 1UL << 0,
NSDataBase64Encoding76CharacterLineLength = 1UL << 1,

// Use zero or more of the following to specify which kind of line ending is inserted. The default line ending is CR LF.
NSDataBase64EncodingEndLineWithCarriageReturn = 1UL << 4,
NSDataBase64EncodingEndLineWithLineFeed = 1UL << 5,

} NS_ENUM_AVAILABLE(10_9, 7_0);

所以我可以选择行长 64 或 76。用于基本身份验证的 base64 编码没有行长限制,所以我该如何处理。

最佳答案

如果您不选择任何选项,line endings are not added .

[myData base64EncodedStringWithOptions:0]; // One long string

关于ios - 使用 ios8/ios9 api 的 base64 编码没有行长度限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32806200/

相关文章:

ios - 如何通过 IOBluetooth/CoreBluetooth 使用服务请求?

ios - 苹果手机 : How do I add a text view that the font size decreases to fit text view size when needed to

objective-c - UILabel 有最大高度吗?

iOS8 Swift - TableView - Controller 不符合协议(protocol) UITableViewDataSource

ios - "Missing argument parameter ' 队列 ' in call"

ios - 如何下载已弃用的 pod

ios - AdMob 在已发布的应用程序中显示测试插页式广告

ios - 运行时更改 UITabBar

iphone - 未在文档目录文件夹中获取图像

ios - UITableViewCell indentationLevel 在 iOS 8 中不起作用