Base64 Encoding/Decoding with Swift 2

后端 未结 1 1951
别那么骄傲
别那么骄傲 2021-02-10 02:01

My code was working well on Xcode 6.4 with Swift 1.2:

 var imageData = UIImageJPEGRepresentation(firstImageView.image!, 0.2)

 let base64String = imageData!.base         


        
1条回答
  •  被撕碎了的回忆
    2021-02-10 02:32

    You should use .Encoding64CharacterLineLength instead of .allZeros:

    let imageData = UIImageJPEGRepresentation(firstImageView.image!, 0.2)
    
    let base64String = imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
    

    0 讨论(0)
提交回复
热议问题