senty senty - 1 year ago 99
Swift Question

Decoding base64String value returns nil

I am trying to get an UIImage from base64String but I am facing an interesting problem. Even though the encoded string is full, decoding it returns nil.

let base64String = imageFilePath as! String
print(base64String) // returns encoded value

let decodedData = NSData(base64EncodedString: base64String, options: NSDataBase64DecodingOptions(rawValue: 0))
print(decodedData) // returns nil

Edit: It goes like

24wKiOQeetKPWmsx3AjtQMe+cDApoOTinCTOOKUsF5osIbtK800E5yKRySeeKFf ZQA5m79KkjYHr1qMupHWkbJGVoGTE0majXceT0qQkAUCGEUo5GKYOT81S5AOKEND

Answer Source

You can try this code:

let decodedData = NSData(base64EncodedString: base64String, options:NSDataBase64DecodingOptions.IgnoreUnknownCharacters)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download