2

On Android, I have part of the code that's doing Base64.encodeToString(b, Base64.NO_WRAP) where b is a bytes array. What is the equivalent of this in the iOS world?

Pinch
  • 2,768
  • 3
  • 28
  • 44
  • Apple does not supply base64 encoding, you must find and use a 3rd party solution. It seems that Apple does not approve of base64 encoding--perhaps it is to googley? Year after year we Radar requests for it and Apple responds with a deathly silence. – zaph Sep 17 '13 at 01:20
  • possible duplicate of [How do I do base64 encoding on iphone-sdk?](http://stackoverflow.com/questions/392464/how-do-i-do-base64-encoding-on-iphone-sdk) – zaph Sep 17 '13 at 01:32
  • 1
    What's the solution? i need no wrap data – Crossle Song May 03 '15 at 14:43

2 Answers2

0

See if Matt Gallagher's base64 code will work for you. I have used it an trust it to be correct. See the section "Handling Base64 on the iPhone".

zaph
  • 111,848
  • 21
  • 189
  • 228
0

iOS

func base64EncodedStringWithOptions(_ options:NSDataBase64EncodingOptions)-> String

Available in iOS 7.0 and later.

Constants Encoding64CharacterLineLength Set the maximum line length to 64 characters, after which a line ending is inserted.

Encoding76CharacterLineLength Set the maximum line length to 76 characters, after which a line ending is inserted.

EncodingEndLineWithCarriageReturn When a maximum line length is set, specify that the line ending to insert should include a carriage return.

EncodingEndLineWithLineFeed When a maximum line length is set, specify that the line ending to insert should include a line feed.

Android

NO_WRAP

Added in API level 8 int NO_WRAP Encoder flag bit to omit all line terminators (i.e., the output will be on one long line).

Looks like you want to use base64EncodedStringWithOptions and NOT include any of the options since all of the iOS options contain some kind of line terminator.

Bryan Bryce
  • 1,310
  • 1
  • 16
  • 29