我有一个表示abase64
的字符串。
我想在网络视图中显示它,但我不知道如何做得好。
我该如何处理?我需要先将字符串转换为数据吗?
最佳答案
请尝试下面的代码。
if let decodeData = NSData(base64EncodedString: base64String, options: .IgnoreUnknownCharacters) {
yourWebView.loadData(decodeData, MIMEType: "application/pdf", textEncodingName: "utf-8", baseURL: NSURL(fileURLWithPath: ""))
} // since you don't have url, only encoded String
斯威夫特4.0
if let decodeData = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters) {
yourWebView.load(decodeData, mimeType: "application/pdf", textEncodingName: "utf-8", baseURL: URL(fileURLWithPath: ""))
} // since you don't have url, only encoded String