What is the need to encode data with method base64EncodedStringWithOptions?

时间:2016-10-20 13:10:05

标签: ios objective-c base64

In one of my iOS projects, due to inconsistency by many developers, I am facing a issue due to incorrect encoding.

Mostly I found that the NSData object is encoded using the method base64EncodedStringWithOptions. The problem is that different parameters are passed for this method, namely:

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,

NSDataBase64EncodingEndLineWithCarriageReturn = 1UL << 4,
NSDataBase64EncodingEndLineWithLineFeed = 1UL << 5,

} NS_ENUM_AVAILABLE(10_9, 7_0);

The issue got solved when I replaced NSDataBase64Encoding64CharacterLineLength with NSDataBase64Encoding76CharacterLineLength.

Questions is: how to select which kind of NSDataBase64EncodingOptions to be used. What is the consequence of using option with no parameter (0). What is the best practice?

0 个答案:

没有答案