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GIDEuNS4zKQovQ3JlYXRpb25EYXRlIChEOjIwMTkwMTE4MTQyNDQxKzAxJzAwJykKPj4KZW5kb2JqCjIwIDAgb2JqCjw8Ci9UeXBlIC9DYXRhbG9nCi9QYWdlcyAxIDAgUgovT3BlbkFjdGlvbiBbMyAwIFIgL0ZpdEggbnVsbF0KL1BhZ2VMYXlvdXQgL09uZUNvbHVtbgo+PgplbmRvYmoKeHJlZgowIDIxCjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDI0NyAwMDAwMCBuIAowMDAwMDAyMDY0IDAwMDAwIG4gCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwMDEyNCAwMDAwMCBuIAowMDAwMDAwMzA0IDAwMDAwIG4gCjAwMDAwMDA0MjkgMDAwMDAgbiAKMDAwMDAwMDU1OSAwMDAwMCBuIAowMDAwMDAwNjkyIDAwMDAwIG4gCjAwMDAwMDA4MjkgMDAwMDAgbiAKMDAwMDAwMDk1MiAwMDAwMCBuIAowMDAwMDAxMDgxIDAwMDAwIG4gCjAwMDAwMDEyMTMgMDAwMDAgbiAKMDAwMDAwMTM0OSAwMDAwMCBuIAowMDAwMDAxNDc3IDAwMDAwIG4gCjAwMDAwMDE2MDQgMDAwMDAgbiAKMDAwMDAwMTczMyAwMDAwMCBuIAowMDAwMDAxODY2IDAwMDAwIG4gCjAwMDAwMDE5NjggMDAwMDAgbiAKMDAwMDAwMjMxMiAwMDAwMCBuIAowMDAwMDAyMzk4IDAwMDAwIG4gCnRyYWlsZXIKPDwKL1NpemUgMjEKL1Jvb3QgMjAgMCBSCi9JbmZvIDE5IDAgUgovSUQgWyA8QTY4MzdFOTVEMjNDNTYxOEM0MTdFQ0UyMzRDNzI2OEE+IDxBNjgzN0U5NUQyM0M1N
但是我无法在Swift 4中解码base64字符串。
几个在线工具完全可以解码字符串,Safari可以打开URL,但是Swift不能这样解码:
let base64Encoded = "JVBERi0xLjMKJbrfrOAKMyAwIG9iago8PC9UeXBlIC9QYW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ci9UeXBlIC9DYXRhbG9nCi9QYWdlcyAxIDAgUgovT3BlbkFjdGlvbiBbMyAwIFIgL0ZpdEggbnVsbF0KL1BhZ2VMYXlvdXQgL09uZUNvbHVtbgo+PgplbmRvYmoKeHJlZgowIDIxCjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDI0NyAwMDAwMCBuIAowMDAwMDAyMDY0IDAwMDAwIG4gCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwMDEyNCAwMDAwMCBuIAowMDAwMDAwMzA0IDAwMDAwIG4gCjAwMDAwMDA0MjkgMDAwMDAgbiAKMDAwMDAwMDU1OSAwMDAwMCBuIAowMDAwMDAwNjkyIDAwMDAwIG4gCjAwMDAwMDA4MjkgMDAwMDAgbiAKMDAwMDAwMDk1MiAwMDAwMCBuIAowMDAwMDAxMDgxIDAwMDAwIG4gCjAwMDAwMDEyMTMgMDAwMDAgbiAKMDAwMDAwMTM0OSAwMDAwMCBuIAowMDAwMDAxNDc3IDAwMDAwIG4gCjAwMDAwMDE2MDQgMDAwMDAgbiAKMDAwMDAwMTczMyAwMDAwMCBuIAowMDAwMDAxODY2IDAwMDAwIG4gCjAwMDAwMDE5NjggMDAwMDAgbiAKMDAwMDAwMjMxMiAwMDAwMCBuIAowMDAwMDAyMzk4IDAwMDAwIG4gCnRyYWlsZXIKPDwKL1NpemUgMjEKL1Jvb3QgMjAgMCBSCi9JbmZvIDE5IDAgUgovSUQgWyA8QTY4MzdFOTVEMjNDNTYxOEM0MTdFQ0UyMzRDNzI2OEE+IDxBNjgzN0U5NUQyM0M1N"
let decodeData = Data(base64Encoded: base64Encoded, options: Data.Base64DecodingOptions.ignoreUnknownCharacters)!
我阅读了有关填充字符串的解决方案,但是即使添加=字符以使字符计数为4的倍数,我也无法解码该字符串。base64字符串或我的代码怎么了?>