我有base64
字符串代表PDF
。
我想在Webview中显示它,但我不知道如何做得好。
我该如何处理?我是否需要先将String转换为数据?
答案 0 :(得分:4)
请尝试以下代码。
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
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